es-toolkit/docs/reference/compat/math/floor.md
D-Sketon 34fcd212fa
feat(compat): implement ceil/floor/round (#510)
* feat(compat): implement ceil/floor/round

* Simplify

---------

Co-authored-by: Sojin Park <raon0211@toss.im>
2024-09-13 15:24:43 +09:00

1017 B
Raw Permalink Blame History

floor

::: info This function is only available in es-toolkit/compat for compatibility reasons. It either has alternative native JavaScript APIs or isnt fully optimized yet.

When imported from es-toolkit/compat, it behaves exactly like lodash and provides the same functionalities, as detailed here. :::

Computes number rounded down to precision.

This function takes a number and an optional precision value, and returns the number rounded down to the specified number of decimal places.

Signature

function floor(number: number | string, precision: number | string = 0): number;

Parameters

  • number (number | string): The number to round down.
  • precision (number | string, Optional): The precision to round down to, defaults to 0.

Returns

(number): The rounded down number.

Example

import { floor } from 'es-toolkit/compat';

floor(4.006); // => 4
floor(0.046, 2); // => 0.04
floor(4060, -2); // => 4000