JS Built-ins
← Math178 / 215
Mathroundintermediate

Math.round() β€” -4.5 rounds to -4

πŸ“– Usage Example
// Round to nearest integer (ties go up)
Math.round(4.5)   // β†’ 5
Math.round(4.4)   // β†’ 4

Use Math.round() to round a number to the nearest integer, with ties (.5) rounding up.

Math.round()

Returns the value of a number rounded to the nearest integer.

Challenge: Verify that Math.round(-4.5) returns -4 (rounds toward +Infinity).

πŸ’‘ Hints (1)
  • β€’ Math.round always rounds toward +Infinity at .5, so -4.5 β†’ -4 (not -5)