human-number
v2.0.4
Published
Convert number to a human readable string: `13500` → `13.5K`
Downloads
19,933
Maintainers
Readme
human-number
Convert number to a human readable string (
13500
→13.5K
) based on SI prefixes.
Install
$ npm install human-number --save
Usage
const humanNumber = require('human-number')
humanNumber(100) // 100
humanNumber(1_000) // 1K
humanNumber(1_500) // 1.5K
humanNumber(10_000) // 10K
humanNumber(10_500) // 10.5K
humanNumber(100_000) // 100K
humanNumber(100_500) // 100.5K
humanNumber(1_000_000) // 1M
humanNumber(1_500_000) // 1.5M
humanNumber(1_000_000_000) // 1B
humanNumber(1_500_000_000) // 1.5B
humanNumber(1_000_000_000_000) // 1T
humanNumber(1_500_000_000_000) // 1.5T
You can pass a mapper as second parameter:
const humanNumber = require('human-number')
humanNumber(100, n => Number.parseFloat(n).toFixed(1)) // '100.0'
License
human-number © Kiko Beats, released under the MIT License. Authored and maintained by Kiko Beats with help from contributors.
kikobeats.com · GitHub Kiko Beats · Twitter @Kikobeats