pink three pointed crown logo

StyleKing.biz

StyleKing.biz

JavaScript Math.round

The Math.round() method returns a value rounded to the nearest whole number.

Description

The round() static method of the Math object rounds a number to the nearest whole number. If the part after the decimal point is more than 0.5, it rounds up to the next whole number. If the part after the decimal point is less than 0.5, it rounds down to the current whole number. When the part after the decimal point is exactly 0.5, it rounds up (towards the larger whole number).

Parameters

  1. Number
    A numeric value whose rounded value will be returned.

Return Type

A Number or Nan.

Examples

// Sample JavaScript
Math.round(42.5); // 43
Math.round(42.4); // 42
Math.floor(42.5); // 42
Math.ceil(42.4);  // 43

See Also

  • Math.ceil()
    Always rounds up
  • Math.floor()
    Always rounds down
  • Number.toFixed()
    Value with the specified number of decimal places.
  • Number.toPrecision()
    Value to specified number of significant digits.

Full Developer Reference

Attribution