Make short numbers from long numbers
- Supports space before sufix.
- Include type definitions.
$ npm install short-numbers
const shortNumbers = require('short-numbers');
shortNumbers('1000')
// => '1K'
shortNumbers(1000)
// => '1K'
shortNumbers('10300')
// => '10.3K'
shortNumbers('1000000')
// => '1M'
shortNumbers('1000000000')
// => '1B'
shortNumbers('1000000000000')
// => '1T'
shortNumbers('10300', { space: true })
// => '10.3 K'
shortNumbers('1000000', { m: 'million', space: true })
// => '1 million'
Type: string
| number
The input number you'd like to convert to a short number. It must be a parsable to number
string or a number.
Type: object
Type: string
Default: 'K'
Set the value of the k which is the prefix 'kilo'.
Type: string
Default: 'M'
Set the value of the m which is the prefix 'million'.
Type: string
Default: 'B'
Set the value of the b which is the prefix 'billion'.
Type: string
Default: 'T'
Set the value of the t which is the prefix 'trillion'.
Type: string
Default: true
Specify if the contains space before sufix.
- Supports for plural sufixes.
Current behavior
shortNumbers('2000000', { m: 'million like', space: true })
// => 2 million like
Desired behavior
// => 2 million likes
- Suport for prefix. An optional string to prepend to the value, e.g.
'$'
.
MIT © Abraham Hernandez