npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

number-to-locale-text

v1.0.1

Published

number, localization, typescript

Downloads

5

Readme

Number to String Conversion

This repository provides a utility for converting numbers into their written form in multiple languages.
It supports various locales and allows the user to define a default locale for the conversion.

Features

  • Convert numbers to words in multiple languages.
  • Supports localization for several languages (English, Arabic, French, German, Spanish, Turkish, Persian).
  • Handles decimal and negative numbers.
  • Customizable locale definitions for fine-grained control over formatting.

Installation

You can install the package via npm:

npm install number-to-locale-text

or using yarn:

yarn add number-to-locale-text

Alternatively, include it directly in your project.


Usage

Setting the Default Locale

Before converting numbers, you need to set the default locale:

import { setDefaultLocale, Locales } from 'number-to-locale-text';

// Set default locale to English
await setDefaultLocale(Locales.EN);

Converting Numbers to Words

Once a locale is set, you can use numberToString:

import { numberToString } from 'number-to-locale-text';

const result = numberToString(1234.56);
console.log(result); 
// Output depends on the default locale

Available Locales

The available locales are defined in the Locales enum:

export enum Locales {
    FA = "fa", // Persian
    EN = "en", // English
    AR = "ar", // Arabic
    FR = "fr", // French
    DE = "de", // German
    ES = "es", // Spanish
    TR = "tr", // Turkish
}

To use a specific locale, set it with setDefaultLocale.


Examples by Locale

Below are example outputs for the same numbers (25, 138, 1205, 25.34, -42) in different locales:

🇮🇷 Persian (fa)

await setDefaultLocale(Locales.FA);

console.log(numberToString(25));     // بیست و پنج
console.log(numberToString(138));    // یکصد و سی و هشت
console.log(numberToString(1205));   // یک هزار و دویست و پنج
console.log(numberToString(25.34));  // بیست و پنج و سی و چهار صدم
console.log(numberToString(-42));    // منفی چهل و دو

🇬🇧 English (en)

await setDefaultLocale(Locales.EN);

console.log(numberToString(25));     // twenty five
console.log(numberToString(138));    // one hundred and thirty eight
console.log(numberToString(1205));   // one thousand two hundred and five
console.log(numberToString(25.34));  // twenty five point thirty four
console.log(numberToString(-42));    // minus forty two

🇸🇦 Arabic (ar)

await setDefaultLocale(Locales.AR);

console.log(numberToString(25));     // خمسة و عشرون
console.log(numberToString(138));    // مائة و ثمانية و ثلاثون
console.log(numberToString(1205));   // ألف و مائتان و خمسة
console.log(numberToString(25.34));  // خمسة و عشرون و أربعة و ثلاثون مئة
console.log(numberToString(-42));    // سالب اثنان و أربعون

🇫🇷 French (fr)

await setDefaultLocale(Locales.FR);

console.log(numberToString(25));     // vingt-cinq
console.log(numberToString(138));    // cent trente-huit
console.log(numberToString(1205));   // mille deux cent cinq
console.log(numberToString(25.34));  // vingt-cinq virgule trente-quatre
console.log(numberToString(-42));    // moins quarante-deux

🇩🇪 German (de)

await setDefaultLocale(Locales.DE);

console.log(numberToString(25));     // fünfundzwanzig
console.log(numberToString(138));    // einhundertachtunddreißig
console.log(numberToString(1205));   // eintausendzweihundertfünf
console.log(numberToString(25.34));  // fünfundzwanzig Komma vierunddreißig
console.log(numberToString(-42));    // minus zweiundvierzig

🇪🇸 Spanish (es)

await setDefaultLocale(Locales.ES);

console.log(numberToString(25));     // veinticinco
console.log(numberToString(138));    // ciento treinta y ocho
console.log(numberToString(1205));   // mil doscientos cinco
console.log(numberToString(25.34));  // veinticinco coma treinta y cuatro
console.log(numberToString(-42));    // menos cuarenta y dos

🇹🇷 Turkish (tr)

await setDefaultLocale(Locales.TR);

console.log(numberToString(25));     // yirmi beş
console.log(numberToString(138));    // yüz otuz sekiz
console.log(numberToString(1205));   // bin iki yüz beş
console.log(numberToString(25.34));  // yirmi beş virgül otuz dört
console.log(numberToString(-42));    // eksi kırk iki

Custom Locale Files

Locales are loaded dynamically from JSON files inside the locales/ folder.
You can modify existing ones or create new locales.

Each JSON must follow the Locale interface:

{
  "delimiter": " ",
  "zero": "zero",
  "negative": "minus",
  "letters": [
    ["", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"],
    ["ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"],
    ["", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"],
    ["", "hundred", "two hundred", "three hundred", "four hundred", "five hundred", "six hundred", "seven hundred", "eight hundred", "nine hundred"],
    ["", "thousand", "million", "billion"]
  ],
  "decimalSuffixes": ["tenth", "hundredth", "thousandth"]
}

Handling Negative Numbers and Decimals

  • Negative numbers: Adds the locale’s negative string.
  • Decimals: Appends fractional part using decimalSuffixes if defined, otherwise falls back to "." + digits.

Error Handling

  • If numberToString is called before setting a default locale:
Error: Locale is not set. Please set a default locale using setDefaultLocale.
  • If you set an unsupported locale:
Error: Locale <locale> is not supported.

Locale Configuration

export interface Locale {
  delimiter: string;
  zero: string;
  negative: string;
  letters: string[][];
  decimalSuffixes: string[];
}

Contributing

Feel free to fork and contribute by adding new locales or improving conversions.


License

This project is licensed under the MIT License. See the LICENSE file for details.