Round numeric results
Convert measured or calculated decimal values to whole-unit quantities.
JavaScript · Function
Math.round() returns a number rounded to the nearest integer. Exact halves round toward positive infinity, so -3.5 becomes -3 and 3.5 becomes 4.
Math.round() converts its argument to a number and returns the closest integral Number. When two integers are equally close, it chooses the one toward positive infinity, so positive and negative halves behave differently.
Math.round(x)| Name | Type | Description |
|---|---|---|
x | number | The numeric value to round; it is converted to a Number before rounding. |
The value of x rounded to the nearest integer.
const values = [3.49, 3.5, -3.5, -0.1];
const rounded = values.map(Math.round);
console.log(rounded); // [3, 4, -3, -0]Maps Math.round over several values to show ordinary rounding, ties toward positive infinity, and preservation of negative zero.
Convert measured or calculated decimal values to whole-unit quantities.
Choose the nearest integer for display or threshold logic.
Handle signed values while preserving JavaScript's negative-zero behavior when relevant.
Math.ceil()Math.floor()Math.trunc()Object.is()