@3mo/safe-round
v1.0.2
Published
A utility for rounding numbers to a given number of decimals without floating-point errors, also as Math.safeRound.
Readme
Safe Round
A utility for rounding numbers to a given number of decimals without floating-point errors, also as Math.safeRound.
Installation
npm install @3mo/safe-roundimport { safeRound } from '@3mo/safe-round'Usage
<mo-flex gap='4px'>
<code>safeRound(1.005, 2) = ${safeRound(1.005, 2)}</code>
<code>Math.safeRound(-2.5) = ${Math.safeRound(-2.5)}</code>
</mo-flex>Examples
- Comparison — Where
Math.roundandtoFixedtrip over binary floating point or round negative halves toward zero,safeRoundrounds halves away from zero.
API
Exports
| Name | Kind | Description |
| --- | --- | --- |
| safeRound | function | Rounds a number to the given decimals without floating-point errors, halves away from zero. |
Links
License
MIT © 3MO GmbH
