1.0.0 • Published 6 years ago
n2str v1.0.0
N2STR
N2STR is a small package that allow you to convert numbers to a short and readable string
999 => 999
1000 => 1K
15654 => 15.65K
50115130 => 50.11M
Installation
You can install the package by using NPM or Yarn
npm install n2str
yarn add n2str
Usage
You need to import the package in your JS code and then you are good to go!
import n2str from 'n2str';
n2str(432564); // 432.56K
Things to know
- The package will keep 2 decimals if possible (no rounding)
- If a number lower than 1000 is passed, the function will returns the number itself
- Available symbol are K (thousand), M (million) and B (billion)
"Real-Life" example
This package can be useful if you want to:
- display a view count (image/video hosting).
- display an amount of money
Contributing
Do not hesitate to submit an issue or a PR if you have any issue/idea!