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);