Skip to content

Easily format a number to fit in a given space (number of characters).

License

Notifications You must be signed in to change notification settings

Traackr/formaat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Formaat

Bower version NPM version

Number formatter

Easily format a number to fit in a given space (number of characters).

Tested on IE11+, Safari, Firefox, and Chrome. Compatible with Require.js/AMD and NodeJS.

Usage

The formatted number can be generated given a number of characters to fit in. Commas, periods count as half-spaces. If a number cannot be abbreviated, it will be cropped with tildes.

Initialize formaat

The formaat constructor takes a number of characters to fit in. Commas, periods count as half-spaces.

// pass in number of characters to fit in
var formaat = formaat(3.5);

Generate number

Pass in the number to be formatted.

Numbers over a trillion will be formatted as "1T+".

// Generate number
var formatted = formaat.abbrev(8100);

8.1K

Tests

A Mocha test suite is available.

npm install
npm test

About

Easily format a number to fit in a given space (number of characters).

Resources

License

Stars

Watchers

Forks

Packages

No packages published