Round big numbers with arbitrary precision
$ npm install --save smart-round
The module exports a function that let you initialize a rounder function.
maxPrecision
: Amount of significant digits to return.
minDecimals
: Minimum amount of decimals to return.
maxDecimals
: Maximum amount of decimals to return.
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.
const smartRound = require('smart-round')
const rounder1 = smartRound(6, 0, 6)
console.log(rounder1('1234.56789', false)) // '1234.57'
console.log(rounder1('1234.56789', true)) // '1,234.56'
const rounder2 = smartRound(4, 2, 6)
console.log(rounder2('1234', true)) // '1,234.00'
console.log(rounder2('0.000123456', true)) // '0.000123'
A transpiled version is available in es5/index.js
. To use that specific version, this syntax is also supported:
var smartRound = require('smart-round/es5');
MIT