node package manager

number-abbreviate

Abbreviate a number and add unit letters e.g. 2200000 => '2.2m'

number-abbreviate

Abbreviate a number and add unit letters e.g. 2200000 => '2.2m'

Code inspired by http://stackoverflow.com/questions/2685911/is-there-a-way-to-round-numbers-into-a-reader-friendly-format-e-g-1-1k

  var NumAbbr = require('number-abbreviate')
 
  var numAbbr = new NumAbbr()
 
  numAbbr.abbreviate(12, 1)
  // => 12 
  numAbbr.abbreviate(0, 2)
  // => 0 
  numAbbr.abbreviate(1234, 0)
  // => 1k 
  numAbbr.abbreviate(34567, 2)
  // => 34.57k 
  numAbbr.abbreviate(918395, 1)
  // => 918.4k 
  numAbbr.abbreviate(2134124, 2)
  // => 2.13m 
  numAbbr.abbreviate(47475782130, 2)
  // => 47.48b 
  numAbbr.abbreviate(-1234, 0)
  // => -1k 
  numAbbr.abbreviate(-918395, 1)
  // => -918.4k 
  numAbbr.abbreviate(-47475782130, 2)
  // => -47.48b 
  var NumAbbr = require('number-abbreviate')
 
  var numAbbr = new NumAbbr([numberAbbreviations])
 
  numAbbr.abbreviate([number], [decPlaces])

The numberAbbreviations is optional. It can be an array of units, defaulting to ['k', 'm', 'b', 't'].

decPlaces is also optional. It defaults to 0.

Takes a number and the number of decimal places to abbreviate

npm install number-abbreviate --save

bower install number-abbreviate

Dom Harrington

http://stackoverflow.com/questions/2685911/is-there-a-way-to-round-numbers-into-a-reader-friendly-format-e-g-1-1k

Licensed under the New BSD License