Small one-function-lib to round numbers with custom precision. TypeScript ready.
npm install @drag13/round-to
RoundTo function rounds your decimal with selected precesion. It also tries to handle edge cases with floating point using Epsilon shift and nano-robots.
const round = require('@drag13/round-to');
const roundingResult = round(5.4399, 2);
console.assert(roundingResult===5.44);
Feel free to use it with TypeScript
import * as round from '@drag13/round-to';
const roundingResult = round(5.4399, 2);
console.assert(roundingResult===5.44);
npm test
console.assert(roundTo(0.43499999999999994, 2)===0.435);
console.assert(roundTo(Math.PI, 2)===3.14);
Any bug fixing is appreciated. If you want to add new functionality - you're welcome. But KISS it please.