Skip to content

Small library to format numbers approximately ("7.5K", "280M", etc.)

Notifications You must be signed in to change notification settings

mahemoff/approximate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Small JavaScript library to format numbers approximately ("7.5K", "280M", etc.)

Test specimens:
7 ==> '7'
800 ==> '800'
1000 ==> '1K'
1200 ==> '1.2K'
87821 ==> '88K'
412011 ==> '412K'
999949 ==> '999K'
999950 ==> '1M'
1000000 ==> '1M'
6123922 ==> '6.1M'
27969374 ==> '28M'
28001341 ==> '28M'
28061341 ==> '28M'
812192442 ==> '812M'
999949999 ==> '999M'
999950000 ==> '1B'
1000000000 ==> '1B'

Notes:
- Supports negative values too
- Now with options for unit names (e.g. instead of "B", could use "G" or " billion")
- Won't format to sub-integer values for now (0.4 becomes "0", 0.8 becomes "1")

About

Small library to format numbers approximately ("7.5K", "280M", etc.)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published