https://github.com/scurker/thousands
A micro js library for formatting numbers with thousands separator
https://github.com/scurker/thousands
formatting javascript micro-library numbers
Last synced: about 1 year ago
JSON representation
A micro js library for formatting numbers with thousands separator
- Host: GitHub
- URL: https://github.com/scurker/thousands
- Owner: scurker
- License: other
- Created: 2017-01-17T05:43:29.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-17T06:13:37.000Z (over 9 years ago)
- Last Synced: 2025-03-29T11:51:43.278Z (about 1 year ago)
- Topics: formatting, javascript, micro-library, numbers
- Language: JavaScript
- Size: 4.88 KB
- Stars: 13
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# thousands [](https://travis-ci.org/scurker/thousands) [](https://www.npmjs.com/package/thousands)
A micro javascript library for formatting numbers with thousands separator.
#### Why should I use this over [Number.toLocaleString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)?
`Number.toLocaleString()` isn't supported in some browsers (< Safari 9, < IE 11), or if you're running in an older node environment (< 0.12) i18n support is not included. In most cases you will likely want to use `Number.toLocaleString()`, but this library allows you to format numbers no matter what your environment supports.
## Install
```
$ npm install --save thousands
```
## Usage
```js
const thousands = require('thousands');
thousands(1234); // => 1,234
thousands(123456); // => 123,456
thousands('1234.56'); // => 1,234.56
thousands(1234, ' '); // => 1 234
thousands(123456, ' '); // => 123 456
thousands('1234.56', ' '); // => 1 234.56
```
## License
MIT © [Jason Wilson](http://scurker.com)