/number-js-formatter

A Javascript library for formatting regular numbers to a friendly number

Primary LanguageTypeScriptMIT LicenseMIT

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.

Demo

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 coming soon

🔌 Contributing

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