JS Built-ins
← Math118 / 215
Mathfloorbeginner

Math.floor() Leaves Integers Unchanged

πŸ“– Usage Example
// Round down to the nearest integer
Math.floor(4.9)   // β†’ 4
Math.floor(-4.1)  // β†’ -5

Use Math.floor() when you need to round a number down to the nearest whole integer.

Math.floor(x)

When the input is already an integer, Math.floor() returns it unchanged. Math.floor(4) returns 4.

Challenge: Verify that Math.floor() is idempotent for integers.

πŸ’‘ Hints (2)
  • β€’ An integer is already at its floor
  • β€’ floor(n) = n for all integers n