Converts a decimal number using fixed-point notation, avoiding the conversion from number to string of Number.toFixed, and allowing the user to choose the approximation method to be used
npm install fixed-math


sh
npm install --save fixed-math
`
Typings
This package is written in TypeScript and is designed to be compatible with NodeJS 6+.
The following types are exported:
`typescript
export type Method = 'round' | 'ceil' | 'floor';
export type FixedMath = (number: number, precision?: number, method?: Method) => number;
`
How to import
`js
import fixedMath, { Method, FixedMath } from 'fixed-math';
`
Usage
Just take a look at the signature of the method:
`typescript
/**
* @param number The float number to approximate
* @param precision The number of digits (it must be an integer value) after the decimal point.
* It defaults to 2 digits.
@param method The name of the Math. method used as approximation.
* You can choose between 'round', 'ceil' and 'floor'.
*/
const fixedMath: FixedMath = (number, precision = 2, method = 'round');
`
Please take a look at the tests to check out every possible nuance and example of using this package.
Related packages
- is-equally-spaced: utility function that given an array of numbers, evaluates wether or not every element is equally spaced, i.e. if every subsequent couple of numbers in the array has the same distance.
Contributing
Of course PRs are welcome! Before contributing, however, please be sure to run npm run test:ci or yarn test:ci`,