Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

number-abbreviate

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

number-abbreviate

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

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.7K
decreased by-14.33%
Maintainers
1
Weekly downloads
 
Created
Source

number-abbreviate

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

build status

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

Example

Simple/shorthand mode:

var abbreviate = require('number-abbreviate')
abbreviate(1000) // => 1k
abbreviate(1111, 0) // => 1k
abbreviate(1111, 1) // => 1.1k
abbreviate(1111, 2) // => 1.11k

Class/constructor mode:

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

Usage

var NumAbbr = require('number-abbreviate')

var numAbbr = new NumAbbr([units])

numAbbr.abbreviate([number], [decPlaces])

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

decPlaces is also optional. It defaults to 0.

numAbbr.abbreviate([number], [decPlaces])

Takes a number and the number of decimal places to abbreviate

Installation

npm install number-abbreviate --save

bower install number-abbreviate

Credits

Dom Harrington

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

License

Licensed under the New BSD License

Keywords

FAQs

Package last updated on 08 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc