Usage
import { round } from 'ngwr/utils';
round(0.1 + 0.2, 2); // 0.3
round(1.005, 2); // 1.01
round(7.4); // 7Why ngwr provides this
Math.round((v) * 100) / 100 mis-rounds boundary values because of binary floating point — 1.005 becomes 1 instead of 1.01. Adding Number.EPSILON before scaling fixes the boundary cases; the slider and input-number components rely on it for step math.
// Native:
Math.round(1.005 * 100) / 100; // 1 ← wrong
// ngwr:
round(1.005, 2); // 1.01API
| Name | Description | Type | Default |
|---|---|---|---|
round | Rounds value to decimals fraction digits. | (value: number, decimals = 0) => number | — |