CKTIS / JavaScript
Math.floor: round downward
Math.floor converts its argument to Number and returns the greatest integral numeric value that is not greater than the input.
Version: ECMAScript 1 onward; example target: Node.js 24.22.2
Syntax
Math.floor(x)Math.floor(x) applies ToNumber and rounds toward -Infinity. Thus floor(7.9) is 7, while floor(-7.1) is -8. An integral number and ±Infinity are unchanged, and NaN yields NaN. floor(-0) preserves -0, whereas every finite number between -1 and 0 yields -1.
A numeric string is converted, null becomes 0, and a missing argument yields NaN. A Symbol or BigInt throws TypeError; an object can invoke valueOf or toString. The result remains a Number and cannot restore digits already lost to IEEE 754 precision.
The function is not a constructor and has been standard since ECMAScript 1. It is useful for bucket indexes such as Math.floor(timestamp / windowMs). For negative data, do not replace it blindly with Math.trunc: truncation rounds toward zero and selects a different bucket. Validate a positive, nonzero bucket size before division.
Examples
const windowMs = 1000;
const timestamps = [1999, 2000, -1];
console.log(timestamps.map((value) => Math.floor(value / windowMs)).join(","));
console.log(Math.floor(7.9), Math.floor(-7.1));
console.log(Object.is(Math.floor(-0), -0), Math.floor(-0.25));
console.log(Math.floor("3.9"), Math.floor(null));
console.log(Number.isNaN(Math.floor()), Math.floor(-Infinity));
try { Math.floor(1n); } catch (error) { console.log(error instanceof TypeError); }Result
1,2,-1 7 -8 true -1 3 0 true -Infinity true