thousandify
v1.0.3
Published
Currency thousand format
Downloads
368
Maintainers
Readme
thousandify
Currency thousand format
Installation
$ npm install thousandify
Usage
const thousandify = require('thousandify');
// 123456 -> '123,456'
console.log(thousandify(123456))
// 123456.1 -> '123,456.1'
console.log(thousandify(123456.1))
// 123456.123 -> '123,456.123'
console.log(thousandify(123456.123))
// 123456 -> '123,456.00'
console.log(thousandify(123456, { decimalDigits: 2 }))
// 123456.1-> '123,456.10'
console.log(thousandify(123456.1, { decimalDigits: 2 }))
// 123,456.123 -> '123,456.12'
console.log(thousandify(123456.123, { decimalDigits: 2 }))
// 123456 -> '123 456'
console.log(thousandify(123456, { thousandSeparator: ' ' }))
Syntax
thousandify(currency, option)
currency
Required, <Number | BigInt | String>
option
Optional, the default value is:
{
thousandSeparator: ',',
decimalSeparator: '.',
decimalDigits: false
}
thousandSeparator
:<String>
The separator of thousands number stringdecimalSeparator
:<String>
The decimal separatordecimalDigits
:<Number | Falsy>
Falsy: Do not handle the dicimal
// 123456 -> '123,456' console.log(thousandify(123456)) // 123456.1 -> '123,456.1' console.log(thousandify(123456.1)) // 123456.123 -> '123,456.123' console.log(thousandify(123456.123))
Number: The count of decimal
// 123456 -> '123,456.00' console.log(thousandify(123456, { decimalDigits: 2 })) // 123456.1-> '123,456.10' console.log(thousandify(123456.1, { decimalDigits: 2 })) // 123,456.123 -> '123,456.12' console.log(thousandify(123456.123, { decimalDigits: 2 })) // 123,456.123 -> '123,456' console.log(thousandify(123456.123, { decimalDigits: 0 }))
Run UT
To run the test suite, first install the dependencies, then run npm test
:
$ npm install
$ npm test