floor()
floor(
n,precision):number
Computes number rounded down to precision.
DEPRECATED
Use Math.floor() directly instead.
Parameters
n: number
The number to round down.
precision: number = 0
The precision to round down to. Defaults to 0.
Returns: number
The rounded down number.
See Also
Since
2.0.0
Also known as
floor (Lodash, es-toolkit) · ❌ (Remeda, Radashi, Ramda, Effect, Modern Dash, Antfu)
Example
// ❌ Deprecated approach
floor(4.906); // => 4
floor(0.046, 2); // => 0.04
floor(4060, -2); // => 4000
// ✅ Recommended approach
Math.floor(4.906); // => 4
Math.floor(0.046 * 100) / 100; // => 0.04
Math.floor(4060 / 100) * 100; // => 4000
How it works?
Rounds number down to specified precision.
Deprecated: Use Math.floor() directly.
Native Equivalent
// ❌ floor(value)
// ✅ Math.floor(value)
Use Cases
Round down 📌
Round number down to nearest integer.
Math.floor(4.9); // 4
Math.floor(-4.1); // -5
Calculate index
Calculate array index from ratio.
const index = Math.floor(Math.random() * items.length);