smart-round
Round big numbers with arbitrary precision
Installation
$ npm install --save smart-round
Usage
The module exports a function that let you initialize a rounder function.
smartRound(maxPrecision, minDecimals, maxDecimals)
maxPrecision
: Amount of significant digits to return.
minDecimals
: Minimum amount of decimals to return.
maxDecimals
: Maximum amount of decimals to return.
rounder(number, shouldFormat)
number
: The value to round as any type supported by bignumber.js
package.
shouldFormat
: Whether the returned string should be formatted or not, using accounting
package.
Example
const smartRound = const rounder1 = console // '1234.57'console // '1,234.56' const rounder2 = console // '1,234.00'console // '0.000123'
ES5 support
A transpiled version is available in es5/index.js
. To use that specific version, this syntax is also supported:
var smartRound = ;
License
MIT