I used intl.formatNumber and it gave me what I needed:

formatNumber(1000); // "1,000"

I can then include the km. inside "defaultMessage" and let translators change that should they wish to.

Source: https://github.com/yahoo/react-intl/wiki/API#number-formatting-apis

Answer from Corkscreewe on Stack Overflow
🌐
Format.JS
formatjs.github.io › docs › react-intl
React Intl | FormatJS
Polyfill Intl.NumberFormat with @formatjs/intl-numberformat.
🌐
GitHub
github.com › marciobarrios › react-intl-number-format
GitHub - marciobarrios/react-intl-number-format: Number and currency formatter based on the ECMAScript Internationalization API · GitHub
// In your App.js or similar... import { IntlProvider } from "react-intl-number-format" const intlConfig = { locale: "en-US", options: { currency: "USD", maximumFractionDigits: 2 } } const App = () => ( <IntlProvider config={intlConfig}> ... </IntlProvider> ) // In any other part of your code import { Currency } from "react-intl-number-format" const HelloWorld = () => ( // renders $20,000 (based on the provider config) <Currency>20000</Currency> ) The configuration object that IntlProvider expects is basically matching the arguments from Intl.NumberFormat constructor.
Starred by 16 users
Forked by 2 users
Languages   JavaScript
🌐
Netlify
react-intl-number-format.netlify.app
React Intl Number Format
Number and currency formatter based on the ECMAScript Internationalization API
🌐
npm
npmjs.com › package › react-intl-number-format
react-intl-number-format - npm
Number and currency formatter based on the ECMAScript Internationalization API. Latest version: 1.1.1, last published: 6 years ago. Start using react-intl-number-format in your project by running `npm i react-intl-number-format`. There are no ...
      » npm install react-intl-number-format
    
Published   Dec 02, 2019
Version   1.1.1
Author   Marcio Barrios
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Intl › NumberFormat
Intl.NumberFormat - JavaScript | MDN
Getter function that formats a number according to the locale and formatting options of this Intl.NumberFormat object.
🌐
Formatjs
formatjs.io › docs › react-intl
FormatJS - Internationalize your web apps on the client & server
A modular collection of JavaScript libraries focused on formatting numbers, dates, and strings. Core libraries build on JavaScript Intl built-ins and industry-wide i18n standards. Built-in integrations with React and Vue.
🌐
UNPKG
unpkg.com › browse › react-intl-number-format@1.0.0 › README.md
react-intl-number-format/README.md
```js // In your App.js or similar... import { IntlProvider } from "react-intl-number-format" const intlConfig = { locale: "en-US", options: { currency: "USD", maximumFractionDigits: 2 } } const App = () => ( <IntlProvider config={intlConfig}> ... </IntlProvider> ) // In any other part of your code import { Currency } from "react-intl-number-format" const HelloWorld = () => ( <Currency>20000</Currency> // renders $20,000 (based on the provider config) ) ``` The configuration object that `IntlProvider` expects is basically matching [the arguments from Intl.NumberFormat constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat#Parameters).
Find elsewhere
🌐
Format.JS
formatjs.github.io › docs › intl
Intl | FormatJS
React Intl has a Message Descriptor concept which is used to define your app's default messages/strings and is passed into formatMessage.
🌐
DEV Community
dev.to › josephciullo › simplify-currency-formatting-in-react-a-zero-dependency-solution-with-intl-api-3kok
Simplify Currency Formatting in React: A Zero-Dependency Solution with Intl API - DEV Community
September 18, 2025 - The Intl.NumberFormat API works by taking a locale and an optional set of formatting options to produce a localized string representation of a number. When instantiated, it creates a formatter that applies the specified rules, such as currency, ...
Top answer
1 of 2
2

Javascript has a number formatter (part of the Internationalization API).

    // Quick Solution With Intl.NumberFormat
    const update = (val: any) => {
    var formatter = new Intl.NumberFormat("en-US");         // Intl language tag,
    updateValue(formatter.format(val.replace(/,/g, "")));   //Remove ',' to format number again
    };

Code Snippet:

// Intl.NumberFormat With React State Update

var currentVal = 0;
...
const update = (event: any) => {
   /**
   https://stackoverflow.com/questions/35535688/stop-cursor-jumping-when-formatting-number-in-react
   https://github.com/facebook/react/issues/955
   */
   const caret = event.target.selectionStart
      const element = event.target
         window.requestAnimationFrame(() => {
         element.selectionStart = caret
         element.selectionEnd = caret
      })
   // -- Stop cursor jumping when formatting number in React

   var val = event.target.value.replace(/(\..*)\./g, '$1') //Replace Multiple Dot(.)
   var x = Number(val.replace(/,/g, ""));
   if (currentVal != x) {
      var formatter = new Intl.NumberFormat("en-US", { minimumFractionDigits:2});
      currentVal = formatter.format(x);
      updateValue(currentVal);
   }else{
      updateValue(val);
   }
 };

 return (<input type="text" value={value} onChange={e => update(e)} />);

Note : Code Snippet gives you an idea to format numbers, You need to handle few more use-cases for production.

Also check the react-number-format, Which may suit for your application.

Reference :

  • Intl.NumberFormat vs Number.prototype.toLocaleString
  • How can I format numbers as dollars currency string in JavaScript?
  • Intl.NumberFormat | MDN
2 of 2
0

The problem is in

const x = Number(val);

when you evaluate Number("32,423,343"), a string including commas Js will throw an error... The correct way would be sending the number without commas.. Number("32432343") To solve it you can add this line to remove the commas, before evaluating to a Number..

val = val.replace(/,/g, '');

https://codesandbox.io/s/r0vm8nxvjo

🌐
GitHub
github.com › taggon › react-native-intl
GitHub - taggon/react-native-intl: React Native module ships native Intl implementation and Translation extension
Like the JavaScript objects, create an instance with/without a locale identifier and call its format method. Unlike JavaScript, the method returns a Promise because React Native's JS-Native bridge should work asynchronous. var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0)); new Intl.DateTimeFormat('en-US').format(date).then( str => console.log(str) );
Starred by 48 users
Forked by 16 users
Languages   Java 45.7% | Objective-C 39.3% | JavaScript 15.0% | Java 45.7% | Objective-C 39.3% | JavaScript 15.0%
🌐
npm
npmjs.com › package › react-intl
react-intl - npm
Internationalize React apps. This library provides React components and an API to format dates, numbers, and strings, including pluralization and handling translations.. Latest version: 8.1.3, last published: a month ago.
      » npm install react-intl
    
Published   Feb 03, 2026
Version   8.1.3
Author   Eric Ferraiuolo
🌐
GitHub
github.com › formatjs › formatjs
GitHub - formatjs/formatjs: The monorepo home to all of the FormatJS related libraries, most notably react-intl. · GitHub
The monorepo home to all of the FormatJS related libraries, most notably react-intl. - formatjs/formatjs
Starred by 14.7K users
Forked by 1.4K users
Languages   TypeScript 69.5% | Rust 20.3% | Starlark 7.4% | JavaScript 1.3% | Java 0.6% | Shell 0.5%
🌐
Localizely
localizely.com › i18n-questions › react › how-to-format-numbers-in-react-app
How to format numbers in React app?
let number = 123456.789; let enFormatter = new Intl.NumberFormat('en-US', { style: 'decimal' }); console.log(enFormatter.format(number)); // 123,456.789 let deFormatter = new Intl.NumberFormat('de-DE', { style: 'decimal' }); console.log(deFormatter.format(number)); // 123.456,789 · To learn more about formatting numbers using the JavaScript Intl object, you can check out this article. Additionally, if you're interested in formatting numbers with the react-intl library, this article may provide further insights.
🌐
CodePen
codepen.io › maqnus › pen › KGzywv
Intl NumberFormat by LANGUAGE_BY_LOCALE
... <div class="container"> <div class="jumbotron"> <div class="page-header"> <h1>Intl NumberFormat <small>by LANGUAGE_BY_LOCALE</small></h1> </div> </div> <div id="app" /></div> </div> ... /* * A simple React component */ class Application extends React.Component { numberFormat(props) { const { num, format, options } = props; try { return new Intl.NumberFormat(format, options).format(num); } catch (e) { return num; } } objToArr(obj) { let arr = []; for (var key in obj) { if (obj.hasOwnProperty(key)) { arr.push({format: key, locale: obj[key] }); } } return arr; } render() { const LANGUAGE_BY_L
🌐
npm
npmjs.com › package › react-number-format
react-number-format - npm
React component to format number in an input or as a text.. Latest version: 5.4.4, last published: a year ago. Start using react-number-format in your project by running `npm i react-number-format`. There are 1635 other projects in the npm registry ...
      » npm install react-number-format
    
Published   Apr 12, 2025
Version   5.4.4
Author   Sudhanshu Yadav
🌐
Format.JS
formatjs.github.io › docs › react-intl › components
Components | FormatJS
React Intl has a set of React components that provide a declarative way to setup an i18n context and format dates, numbers, and strings for display in a web UI.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Intl › NumberFormat › NumberFormat
Intl.NumberFormat() constructor - JavaScript | MDN
const number = 123456.789; console.log( new Intl.NumberFormat("de-DE", { style: "currency", currency: "EUR" }).format( number, ), ); // Expected output: "123.456,79 €" // The Japanese yen doesn't use a minor unit console.log( new Intl.NumberFormat("ja-JP", { style: "currency", currency: "JPY" }).format( number, ), ); // Expected output: "¥123,457" // Limit to three significant digits console.log( new Intl.NumberFormat("en-IN", { maximumSignificantDigits: 3 }).format( number, ), ); // Expected output: "1,23,000"