number-js-formatter
TypeScript icon, indicating that this package has built-in type declarations

0.2.3 • Public • Published

number-js-formatter

Number-js-formatter is a JavaScript library that formats numbers in a human-friendly way.

Perhaps a number like 1000000 is coming from an API you're using or you just want to display a number in a more friendly format; number-js-formatter helps you do that with ease.

Requirements

Make sure you have the following installed:

📦 Install

npm install number-js-formatter
# or
yarn add number-js-formatter
# or
pnpm add number-js-formatter

🚀 Quick start

This library is minimal and doesn't require any configuration.

import { friendlyFormat } from 'number-js-formatter';

const num1 = 1_923_500.156;
const num2 = 1_004_850_000.91332;
const num3 = 1105_830_000_302.9946;

friendlyFormat(num1, { noOfDigitsAfterDecimal: 3 }); // "1.924m"
friendlyFormat(num2, { noOfDigitsAfterDecimal: 4, form: '-ln' }); // "1.0049bln"
friendlyFormat(num3, { noOfDigitsAfterDecimal: 3 }); // "1.106tn"

⚒️ Methods

Method Description
friendlyFormat Formats a number into a human-friendly number.

🔨 Args

Method Args Description
friendlyFormat number: number number to be formatted
FormatOptions object parameters to use for formatting

💡 Features

  • Format options in different short forms.
  • Strongly typed; number-js-formatter is purely written in TypeScript.

Limitations

  • Doesn't support quadrillions numbers
  • Locale support comming soon

🔌 Contributing

Read through our contributing guidelines to learn about our submission process, coding rules, and more.

Package Sidebar

Install

npm i number-js-formatter

Weekly Downloads

89

Version

0.2.3

License

MIT

Unpacked Size

15.5 kB

Total Files

24

Last publish

Collaborators

  • joshx