kmformatter
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

kformatter

Convert numbers to k,m... made easy

Solution to express numbers in k,M,G,T,P,E e.g 1234 to 1.2k, 1243215 to 1.2M

Installation

Using npm:

$ npm i kmformatter

Quick Start

Import the libary and use the format nFormatter(number, decimal)

// load the library
import { formatter } from 'kmformatter';

console.log(formatter(1234, 1));
console.log(formatter(1234, 2));

console.log(formatter(3423567, 1));
console.log(formatter(3423567, 3));

output

$ 1.2k
$ 1.23k
$ 3.4M
$ 3.423M

Special thanks to @Salman A. He wrote the entire solution, I just modified and released it as an npm package for easier usage.

This is the original reddit comment I took the code from.

Package Sidebar

Install

npm i kmformatter

Weekly Downloads

1

Version

0.0.3

License

GPL-3.0

Unpacked Size

38.7 kB

Total Files

5

Last publish

Collaborators

  • khaingmyel