floor
math
Computes number rounded down to precision.
Installation
Import
import { floor } from '@tulx/utils';Source Code
Implementation
/**
* Computes number rounded down to precision.
*
* @param number - The number to round down.
* @param precision - The precision to round down to.
* @returns Returns the rounded down number.
*
* @example
* ```ts
* floor(4.006); // 4
* floor(0.046, 2); // 0.04
* floor(4060, -2); // 4000
* ```
*/
export function floor(number: number, precision: number = 0): number {
const factor = Math.pow(10, precision);
return Math.floor(number * factor) / factor;
}
Example
import { floor } from '@tulx/utils';
floor(4.006); // 4
floor(0.046, 2); // 0.04
floor(4060, -2); // 4000Related Functions
add
Adds two numbers.
ceil
Computes number rounded up to precision.
divide
Divide two numbers.
max
Computes the maximum value of array.
maxBy
This method is like max except that it accepts iteratee which is invoked for each element in array to generate the criterion by which the value is ranked.
mean
Computes the mean of the values in array.