Skip to content

kafipointers/number-fmt

Repository files navigation

number-fmt

A TypeScript library for converting numbers between Indian and International number formatting systems.

Overview

This library is particularly useful for applications that need to display numbers in different regional formats, such as financial applications, e-commerce platforms, or any application serving users across different regions.

Prerequisites

  • Node.js (v18 or higher)
  • pnpm (recommended) or npm/yarn

Installation

npm install number-fmt
# or
pnpm install number-fmt
# or
yarn add number-fmt

For detailed usage examples and API documentation, see the Plugins README.

Contributing

Please read the contributing guide.

License

Licensed under the MIT license.

Usage

Available Utilities

convertToIndianFormat

Converts numbers from International format (or raw numbers) to Indian number format.

Examples:

import { convertToIndianFormat } from "number-fmt";

// Basic conversions
convertToIndianFormat("123456"); // "1,23,456"
convertToIndianFormat("1234567"); // "12,34,567"
convertToIndianFormat("12345678"); // "1,23,45,678"
convertToIndianFormat("123456789"); // "12,34,56,789"

// With existing commas (International format)
convertToIndianFormat("1,234,567"); // "12,34,567"
convertToIndianFormat("123,456"); // "1,23,456"

convertToInternationalFormat

Converts numbers from Indian format (or raw numbers) to International number format.

Examples:

import { convertToInternationalFormat } from "number-fmt";

// Converting from Indian format
convertToInternationalFormat("1,00,000"); // "100,000"
convertToInternationalFormat("12,34,567"); // "1,234,567"
convertToInternationalFormat("1,00,00,000"); // "10,000,000"
convertToInternationalFormat("9,99,99,999"); // "99,999,999"

// Converting from raw numbers (no commas)
convertToInternationalFormat("100000"); // "100,000"
convertToInternationalFormat("1000000"); // "1,000,000"
convertToInternationalFormat("1234567"); // "1,234,567"

About

A TypeScript library for converting numbers between Indian and International number formatting systems.

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors