toFormat
Adds a toFormat
instance method to big.js or decimal.js.
Install
Node.js
$ npm install toformat
Browser
<script src='path/to/big.js'></script>
<script src='path/to/toFormat.js'></script>
Use
Node.js
Big = require('big')
Big = require('toformat')(Big)
x = new Big(9876.54321)
x.toFormat(2)
Big.format.decimalSeparator = ','
x.format.groupSeparator: ' '
x.toFormat(1, { groupSize: 2 })
Browser
toFormat(Big)
x = new Big(9876.54321)
x.toFormat(2)
Further examples:
Decimal.format = {
decimalSeparator: '.',
groupSeparator: ',',
groupSize: 3,
secondaryGroupSize: 0,
fractionGroupSeparator: '',
fractionGroupSize : 0
}
x.toFormat()
x.toFormat(2, 1)
x.format = {
decimalSeparator: ',',
groupSeparator: '',
}
x.toFormat()
format = {
decimalSeparator: '.',
groupSeparator: ' ',
groupSize: 3,
fractionGroupSeparator: ' ',
fractionGroupSize : 5
}
x.toFormat(format)
x.toFormat(4, format)
x.toFormat(2, 1, format)
Test
$ npm test
Licence
MIT