Skip to content
Convert long numbers to pretty, human-readable strings
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Make cli file executable Apr 19, 2019
.eslintrc.yml Refactor Apr 17, 2019
.gitignore
.prettierignore Refactor Apr 17, 2019
.prettierrc.toml Refactor Apr 17, 2019
.travis.yml Add travis CI file May 15, 2019
CHANGELOG.md Update changelog May 15, 2019
LICENSE Initial commit Nov 12, 2015
README.md Add travis build badge to readme May 15, 2019
package-lock.json 3.1.0 May 15, 2019
package.json 3.1.0 May 15, 2019
test.js Update test coverage Apr 19, 2019

README.md

Millify Build Status

Converts long numbers into pretty, human-readable strings.

Before 😒 After 🎉
2000 '2K'
10000 '10k'
42500 '42.5 kg'
1250000 '1.25 MB'
2700000000 '2.7 bil'

Install

Get it on npm:

npm install millify

Command line

millify 10000
# 10K

See millify --help for options.

Programmatic usage

millify(number, options)

const millify = require('millify')

millify(2500)
// 2.5K

millify(1024000, {
  precision: 3,
  lowerCase: true
})
// 1.024m

millify(39500, {
  precision: 2,  
  decimalSeparator: ','
})
// 3,95K

millify(1440000, {
  units: ['B', 'KB', 'MB', 'GB'],
  space: true,
})
// 1.44 MB

Options

Name Type Default Description
precision number 2 Number of significant figures to use
decimalSeparator string '.' Desired decimal separator (e.g. decimal point or comma)
lowerCase boolean false Use lowercase abbreviations
space boolean false Add a space between number and abbreviation
units Array<string> ['', 'K', 'M', 'B', 'T', 'P', 'E'] Unit abbreviations
You can’t perform that action at this time.