react-format-number-shorten
TypeScript icon, indicating that this package has built-in type declarations

1.0.7 • Public • Published

Format number

Installation

npm i react-format-number-shorten

Usage

Import package

import formatNumber from 'react-format-number-shorten';

Basic usage

const pi = 3.14159265359;

console.log(formatNumber(pi)); // 3
console.log(formatNumber(pi, { fixed: 2 })); // 3.14

const price = 125000;
console.log(formatNumber(price)); // 125,000
console.log(formatNumber(price, { decimalSeparator: '.' })); // 125.000

Format with shorten

const money = 1000000;

console.log(formatNumber(money, { shorten: true })); // 1M
console.log(formatNumber(money, { fixed: 2, shorten: true })); // 1.00M
console.log(formatNumber(money, { fixed: 2, shorten: true,  decimalSeparator: ',' })); // 1,00M

Package Sidebar

Install

npm i react-format-number-shorten

Weekly Downloads

1

Version

1.0.7

License

MIT

Unpacked Size

3.47 kB

Total Files

6

Last publish

Collaborators

  • kayden.khuong