JavaScript (ES2026) reference · Math Methods and Constants

JavaScript Math.round() Method

Round a number to the nearest integer; halves round up towards +Infinity, so Math.round(-2.5) is -2.

JavaScript (ES2026) Since ES1

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

Math.round(x)

Parameters

ParameterDescription
x A number.

Return value

An integer.

Examples

Halves round upTry it yourself
console.log(Math.round(2.5), Math.round(2.4), Math.round(-2.5), Math.round(-2.6));

Output

3 2 -2 -3
Round to two decimalsTry it yourself
const price = 19.996;
console.log(Math.round(price * 100) / 100, price.toFixed(2));

Output

20 20.00

Version history

VersionChange
JavaScript ES1Added

In other languages

Was this page helpful?