
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Adds a toFormat
instance method to big.js or decimal.js.
Node.js
$ npm install toformat
Browser
<script src='path/to/big.js'></script>
<script src='path/to/toFormat.js'></script>
Big = require('big')
Big = require('toformat')(Big)
x = new Big(9876.54321)
x.toFormat(2) // '9,876.54'
// Three different ways of setting a formatting property
Big.format.decimalSeparator = ','
x.format.groupSeparator: ' '
x.toFormat(1, { groupSize: 2 }) // '98 76,5'
toFormat(Big)
x = new Big(9876.54321)
x.toFormat(2) // '9,876.54'
// The format object added to the Decimal constructor by this library.
Decimal.format = {
decimalSeparator: '.',
groupSeparator: ',',
groupSize: 3,
secondaryGroupSize: 0,
fractionGroupSeparator: '',
fractionGroupSize : 0
}
x.toFormat() // 123,456,789.987654321
x.toFormat(2, 1) // 123,456,789.98
// Add a format object to a Decimal instance.
x.format = {
decimalSeparator: ',',
groupSeparator: '',
}
x.toFormat() // 123456789,987654321
format = {
decimalSeparator: '.',
groupSeparator: ' ',
groupSize: 3,
fractionGroupSeparator: ' ',
fractionGroupSize : 5
}
// Pass a format object to the method call.
x.toFormat(format) // 123 456 789.98765 4321
x.toFormat(4, format) // 123 456 789.9877
x.toFormat(2, 1, format) // 123 456 789.98
$ npm test
FAQs
Adds a `toFormat` instance method to decimal.js or big.js
The npm package toformat receives a total of 157,812 weekly downloads. As such, toformat popularity was classified as popular.
We found that toformat demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.