A simple number abbreviation tool.
- Zero dependencies.
- Works with any NodeJs projects.
- Simple usage.
$ npm i number-abbreviation
or
$ yarn add number-abbreviation
import { numberAbbr } from 'number-abbreviation';
const thousandNumber = numberAbbr(1234);
// return '1.2K'
const millionNumber = numberAbbr(7654321);
// return '7.7M'
const billionNumber = numberAbbr(9356412313);
// return '9.4B'
const trillionNumber = numberAbbr(5767473333233);
// return '5.8T'
import { numberAbbr } from 'number-abbreviation';
const millionNumber = numberAbbr(7654321, { decimals: 2 });
// return '7.65M'
import { numberAbbr } from 'number-abbreviation';
const mySuffixes = ["Mil", "Milhões", "Bilhões", "Trilhões"];
const millionNumber = numberAbbr(
7654321,
{
suffixes: mySufixes,
suffixSpace: true
}
);
// return '7.6 Milhões'
The "number" to abbreviation.
The "number" of truncated decimals.
Default is: { decimals: 1 }.
An "array" of strings.
It is mandatory to define the value of the 4 indices.
Default is: { suffixes: [ 'K', 'M', 'B', 'T' ] }.
If true, sets a space between the suffix and abbreviated number.
Default is: { suffixSpace: false }.
@anselmodev |
---|