Math

Math.round

Returns the value of a number rounded to the nearest integer

Syntax

JavaScript
Math.round(x)

Parameters

ParameterTypeDescription
xnumberA number

Return Value

The nearest integer to x

Examples

Basic Usage
console.log(Math.round(4.5)); // 5
console.log(Math.round(4.4)); // 4
console.log(Math.round(-4.5)); // -4
Practical Example
function roundTo(num: number, decimals: number) {
  const factor = 10 ** decimals;
  return Math.round(num * factor) / factor;
}
console.log(roundTo(3.14159, 2)); // 3.14
Advanced Usage
const scores = [88.7, 92.3, 75.5];
const rounded = scores.map(Math.round);
console.log(rounded); // [89, 92, 76]

Understanding Math.round

The Math.round method in JavaScript returns the value of a number rounded to the nearest integer. It belongs to the Math object and is one of the most widely used methods for working with math values in modern JavaScript and TypeScript applications.

The method signature is Math.round(x). It accepts 1 parameter: x. When called, it returns the nearest integer to x. Understanding when and how to use round() helps you write more expressive, readable code.

Common use cases for Math.round include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like math-ceil, math-floor, math-trunc, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for Math.round is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More Math Methods

Other methods in the Math object

Related Tools

More Math Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.