What
Spiffy/smart rounding for numbers. Returns string (so you can have a consistent number of decimal places).
Why
Consistent, user friendly friendly formatted numbers. See examples below.
API
spiffyRound(value[, decimal places])
value
Type: Number/String
decimal places
Type: Number
Default: 0
Description: Number of desired decimal places (only applies if decimals are not all 0's)
Installation
npm install --save spiffy-round
Usage
const spiffyRound = ; // value type Number; // '1'; // '1.2'; // '1.20'; // '1.26'; // '1'; // '0'; // '1'; // '-1'; // '0'; // '0'; // '1.01'; // '-1.01' // value type String; // '1'; // '1.2'; // '1.20'; // '1.26'; // '1'; // '0'; // '1'; // '-1'; // '0'; // '0'; // '1.01'; // '-1.01'
ToDo
- handle exponents
- handle alternate decimal separator ','
Contributing
Contributions are welcomed. How to make a contribution:
- Create an issue on Github
- Fork project
- Make changes then use
npm run commit
to commit - Create a pull request