https://github.com/bubkoo/number-abbreviate
🎱 Abbreviate number to a more human-friendly format (3.6K, 6.8M, etc.)
https://github.com/bubkoo/number-abbreviate
abbr abbreviate format human-friendly number units
Last synced: 12 days ago
JSON representation
🎱 Abbreviate number to a more human-friendly format (3.6K, 6.8M, etc.)
- Host: GitHub
- URL: https://github.com/bubkoo/number-abbreviate
- Owner: bubkoo
- License: mit
- Created: 2017-12-11T17:04:37.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-16T08:19:58.000Z (over 2 years ago)
- Last Synced: 2025-05-07T23:45:34.727Z (12 days ago)
- Topics: abbr, abbreviate, format, human-friendly, number, units
- Language: TypeScript
- Homepage:
- Size: 157 KB
- Stars: 9
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Abbreviate Number
Abbreviate number to a more human-friendly format (3.6K, 6.8M, etc.)
## Install
```
npm install numabbr --save
```## Usage
Simple/shorthand mode:
```js
import numabbr from 'numabbr'numabbr(100) // => 100
numabbr(10000) // => 10K
numabbr(-10000) // => -10K
numabbr(1000000) // => 1M
numabbr(1020000) // => 1.02M
numabbr(1000000000) // => 1B
numabbr(1000000000000) // => 1Tnumabbr(123456, { precision: 1 }) // => 123.5K
numabbr(123456, {
precision: 1,
commatize: { division: 2 },
}) // => 1,23.5K
```Class/constructor mode:
```js
import { NumberAbbreviate } from 'numabbr'
const abbr = new NumberAbbreviate({
千: 1000,
万: 10000,
十万: 100000,
百万: 1000000,
千万: 10000000,
亿: 100000000,
})abbr.abbreviate(123) // => 123
abbr.abbreviate(1000) // => 1千
abbr.abbreviate(1234) // => 1.23千
abbr.abbreviate(10000) // => 1万
abbr.abbreviate(12345) // => 1.23万
abbr.abbreviate(123456) // => 1.23十万
```## Options
- **precision** { Number } Default `2`. Specify the precision of decimal part
- **commatize** { Object | Boolean } Default `false`. Specify how to commatize the result
- **division** { Number } Default `3`. Length of each divided parts
- **separator** { Char } Default `,`. Separator of each divided parts## Contributing
Pull requests and stars are highly welcome.
For bugs and feature requests, please [create an issue](https://github.com/bubkoo/number-abbreviate/issues/new).
## License
The scripts and documentation in this project are released under the [MIT License](LICENSE)
s