react-format-number-shorten

react-format-number-shorten JS library on GitHub react-format-number-shorten JS library on npm Download react-format-number-shorten JS library

Format number as string output in React, React Native

Version 1.0.7 License MIT Vulnerabilities 0
react-format-number-shorten has no homepage
react-format-number-shorten JS library on GitHub
react-format-number-shorten JS library on npm
Download react-format-number-shorten JS library
Keywords
formatnumbertypescripreactreactnativereactformatnumberreactnativeformatnumberreactshorten

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