fixed-math
FixedMath is a simple utility function that converts a decimal number using fixed-point notation.
Since it avoids the conversion from number to string that Number.toFixed applies, this package is particularly useful when you care about performance.
It also allows the user to choose the approximation method to be used
Installing
npm install --save fixed-math
yarn add fixed-math
Typings
This package is written in TypeScript and is designed to be compatible with NodeJS 6+.
The following types are exported:
export type Method = 'round' | 'ceil' | 'floor';
export type FixedMath = (number: number, precision?: number, method?: Method) => number;
How to import
import fixedMath, { Method, FixedMath } from 'fixed-math';
Usage
Just take a look at the signature of the method:
const fixedMath: FixedMath = (number, precision = 2, method = 'round');
Contributing
Of course PRs are welcome!