numberparrot v1.1.0

Paste a number, see it read right

Read numbers written in any locale

parseFloat("1.234,56") returns 1.234. numberparrot returns 1234.56. Paste a price, a bank export or a spreadsheet column in the box: it works out the format and reads every value.

API reference GitHub
  • Zero dependencies
  • About 7 kB gzipped
  • Every locale your runtime knows
5 of 5 read
Try

Read as pt-BR, with "," as the decimal separator.

"1.234,56" (row 1) shows that "," is the decimal separator

Confidence92%
  1. 1.234,56 1.234 1234.56
  2. -87,90 -87 -87.9
  3. 12,5 12 12.5
  4. 1.000.000,00 1 1000000
  5. 0,29 0 0.29
5 wrong with parseFloat Sum 1001159.45

World board

One number, 39 locales

Type one number. Every locale writes it its own way, and numberparrot reads every one back.

Try

39wrong with parseFloat

39right with numberparrot

Type a number in any format. Every tile writes it the local way, then reads it back.

parseFloat is wrong in 39 of 39 locales. numberparrot reads every one back.

The Americas

8 locales
  1. en-USJFK

    New York

    1,234,567.891

    parseFloat1

    numberparrot1234567.891

  2. en-CAYYZ

    Toronto

    1,234,567.891

    parseFloat1

    numberparrot1234567.891

  3. fr-CAYUL

    Montréal

    1 234 567,891

    parseFloat1

    numberparrot1234567.891

  4. es-MXMEX

    Mexico City

    1,234,567.891

    parseFloat1

    numberparrot1234567.891

  5. pt-BRGRU

    São Paulo

    1.234.567,891

    parseFloat1.234

    numberparrot1234567.891

  6. es-AREZE

    Buenos Aires

    1.234.567,891

    parseFloat1.234

    numberparrot1234567.891

  7. es-COBOG

    Bogotá

    1.234.567,891

    parseFloat1.234

    numberparrot1234567.891

  8. es-CLSCL

    Santiago

    1.234.567,891

    parseFloat1.234

    numberparrot1234567.891

Europe

14 locales
  1. en-GBLHR

    London

    1,234,567.891

    parseFloat1

    numberparrot1234567.891

  2. de-DEBER

    Berlin

    1.234.567,891

    parseFloat1.234

    numberparrot1234567.891

  3. fr-FRCDG

    Paris

    1 234 567,891

    parseFloat1

    numberparrot1234567.891

  4. es-ESMAD

    Madrid

    1.234.567,891

    parseFloat1.234

    numberparrot1234567.891

  5. it-ITFCO

    Rome

    1.234.567,891

    parseFloat1.234

    numberparrot1234567.891

  6. nl-NLAMS

    Amsterdam

    1.234.567,891

    parseFloat1.234

    numberparrot1234567.891

  7. pt-PTLIS

    Lisbon

    1 234 567,891

    parseFloat1

    numberparrot1234567.891

  8. de-CHZRH

    Zürich

    1'234'567.891

    parseFloat1

    numberparrot1234567.891

  9. sv-SEARN

    Stockholm

    1 234 567,891

    parseFloat1

    numberparrot1234567.891

  10. pl-PLWAW

    Warsaw

    1 234 567,891

    parseFloat1

    numberparrot1234567.891

  11. cs-CZPRG

    Prague

    1 234 567,891

    parseFloat1

    numberparrot1234567.891

  12. uk-UAKBP

    Kyiv

    1 234 567,891

    parseFloat1

    numberparrot1234567.891

  13. ru-RUSVO

    Moscow

    1 234 567,891

    parseFloat1

    numberparrot1234567.891

  14. tr-TRIST

    Istanbul

    1.234.567,891

    parseFloat1.234

    numberparrot1234567.891

Middle East and Africa

6 locales
  1. ar-EGCAI

    Cairo

    ١٬٢٣٤٬٥٦٧٫٨٩١

    parseFloatNaN

    numberparrot1234567.891

  2. ar-SARUH

    Riyadh

    ١٬٢٣٤٬٥٦٧٫٨٩١

    parseFloatNaN

    numberparrot1234567.891

  3. fa-IRIKA

    Tehran

    ۱٬۲۳۴٬۵۶۷٫۸۹۱

    parseFloatNaN

    numberparrot1234567.891

  4. he-ILTLV

    Tel Aviv

    1,234,567.891

    parseFloat1

    numberparrot1234567.891

  5. sw-KENBO

    Nairobi

    1,234,567.891

    parseFloat1

    numberparrot1234567.891

  6. en-ZAJNB

    Johannesburg

    1 234 567,891

    parseFloat1

    numberparrot1234567.891

South Asia

4 locales
  1. en-INBOM

    Mumbai

    12,34,567.891

    parseFloat12

    numberparrot1234567.891

  2. hi-INDEL

    Delhi

    12,34,567.891

    parseFloat12

    numberparrot1234567.891

  3. bn-BDDAC

    Dhaka

    ১২,৩৪,৫৬৭.৮৯১

    parseFloatNaN

    numberparrot1234567.891

  4. ur-PKKHI

    Karachi

    1,234,567.891

    parseFloat1

    numberparrot1234567.891

East Asia and Pacific

7 locales
  1. ja-JPHND

    Tokyo

    1,234,567.891

    parseFloat1

    numberparrot1234567.891

  2. zh-CNPVG

    Shanghai

    1,234,567.891

    parseFloat1

    numberparrot1234567.891

  3. ko-KRICN

    Seoul

    1,234,567.891

    parseFloat1

    numberparrot1234567.891

  4. th-THBKK

    Bangkok

    1,234,567.891

    parseFloat1

    numberparrot1234567.891

  5. vi-VNHAN

    Hanoi

    1.234.567,891

    parseFloat1.234

    numberparrot1234567.891

  6. id-IDCGK

    Jakarta

    1.234.567,891

    parseFloat1.234

    numberparrot1234567.891

  7. en-AUSYD

    Sydney

    1,234,567.891

    parseFloat1

    numberparrot1234567.891

Wrong number or NaN Exactly right Another valid reading Written live by Intl.NumberFormat in your browser and read back by numberparrot 1.1.0.

Departures

Numbers leaving home

Each flight is a number written the local way. The status is what parseFloat did with it on arrival. numberparrot lands every one.

09:41Local time
TimeFlightFromAs writtenparseFloatnumberparrotStatus

On time: parseFloat got it rightDiverted: a wrong numberCancelled: NaN

Use cases

Postcards from where numbers come from

Numbers rarely start in your code. They arrive from shoppers, banks, scrapers and spreadsheets, written the way their sender writes them.

From São Paulo

Checkout and price fields

A shopper types 1.234,56 into your price field. normalizeInput keeps partial input valid while they type and hands you the number on blur.

checkout.ts
normalizeInput("1.234,", "pt-BR").value;
// 1234

From Berlin

CSV and bank exports

A bank export has 1.234,56 in one column and 1,5 in the next. createParser reads every row in one pass, and detect() takes files with no locale.

import.ts
createParser("de-DE").parse("1.234,56");
// 1234.56

From Tokyo

Scraped and pasted prices

Prices arrive with symbols and codes on either side. parseCurrency returns the amount and the ISO code, so you know what you are adding up.

prices.ts
parseCurrency("¥1,235", "ja-JP").currency;
// "JPY"

From London

Accounting reports

Negatives in parentheses, a trailing minus or the Unicode minus sign all read as negative, the way an accountant meant them.

ledger.ts
parse("(1,234.56)", "en-GB");
// -1234.56

From Mumbai

Money in integer cents

toMinorUnits shifts the decimal digits as text, so 0,29 is 29 cents and never 28.999999999999996. Lakh and crore grouping included.

cents.ts
parseCurrency("₹19.99", "en-IN", {
  toMinorUnits: true,
}).amount;
// 1999

From Cairo

Every script

Arabic-Indic, Persian, Devanagari, Bengali, Thai and full width digits read like Latin ones, with their own separators.

digits.ts
parse("١٬٢٣٤٫٥٦", "ar-EG");
// 1234.56

API

Nine functions, one passport each

Every function takes the locale as an argument, so data from Berlin, Mumbai and Cairo can sit side by side. No global state, nothing to register.

parse(input, locale?, options?): number

parse.ts
import { parse } from "numberparrot";

parse("1.234,56", "pt-BR");      // 1234.56
parse("1'234.56", "de-CH");      // 1234.56
parse("12,34,567.89", "en-IN");  // 1234567.89
parse("(1.234,56)", "de-DE");    // -1234.56
parse("15%", "en-US");           // 0.15
parse("1.234,56", "en-US");      // NaN, not an en-US number

parse in the API reference

Install

Node.js 18+, Deno, Bun and every modern browser. ESM, CommonJS and TypeScript types, about 7 kB gzipped.

Terminal
npm install numberparrot

FAQ

Questions at the gate

Pico the parrot
Why not swap the comma for a dot?

Because the meaning of . and , depends on who wrote the number. Swapping fixes "1,5" and breaks "1.234,56" and "1,234". parse(text, locale) reads the separators of that locale from Intl.NumberFormat instead.

What does parseFloat do with 1.234,56?

It reads characters while they look like an English number and stops at the first one that does not, so parseFloat("1.234,56") is 1.234. A wrong number passes every isNaN check, which makes it worse than an error.

How do I get the currency of a price?

parseCurrency("R$ 1.234,56", "pt-BR") returns the amount 1234.56 and the code "BRL". Add toMinorUnits: true to get exact integer cents.

What if I do not know the locale?

Paste it in the box at the top of this page. For one value, detect(text) works out the decimal separator and says when it cannot be sure. For a column, parseColumn(values) lets the clear cells decide for the unclear ones.

Where does it run?

Node.js 18 and newer, Deno, Bun and modern browsers. It has zero dependencies, ships ESM, CommonJS and TypeScript types, and is about 7 kB gzipped.

No match. Try parse, currency, Arabic or pt-BR.