🌐
LinkedIn
linkedin.com › pulse › how-format-number-currency-javascript-techsolutionsclub
How to Format a Number as Currency in JavaScript
November 4, 2022 - For example, 14340 would be $14,340.00 ... and style. And you can convert these numbers into currencies using the Intl.NumberFormat() method in JavaScript....
🌐
Openexchangerates
openexchangerates.github.io › accounting.js
accounting.js: JavaScript number and currency formatting library
Enter any number into the box and choose currency. Uses accounting.formatMoney(): ... <script src="path/to/accounting.js"></script> <script type="text/javascript"> // Library ready to use: accounting.formatMoney(5318008); </script>
Discussions

javascript - How to format numbers as currency strings? - Stack Overflow
I would like to format a price in JavaScript. I'd like a function which takes a float as an argument and returns a string formatted like this: $ 2,500.00 How can I do this? More on stackoverflow.com
🌐 stackoverflow.com
How to handle prices/currency formatting in Javascript?
You have two concerns you need to handle: Monetary calculation Currency formatting Monetary calculations in Javascript are tricky because of the way the numerical standard IEEE 754 works. To avoid incorrect final figures you want to work in cents. You will convert your decimal to cents by multiplying by 100, do all your calculations and then convert back by dividing by 100. You want to output your result in the ideal format for your user. You should use the Intl api for this. It will handle formatting in the conventional way for a given currency and country. As long as you're working with USD it's not a big concern, though it is a useful API, but it's good practice to use it as it will make it easier to handle other currencies later which can be non trivial. For example, Ireland and Germany both use EUR but would display monetary values differently. I wouldn't go anywhere near the toFixed API. More on reddit.com
🌐 r/reactjs
16
7
February 25, 2021
Using regex to remove currency formatting for a number output?
I've been writing a "natural language" regex builder recently, and thought this would be a nice example to test it out on: const currencyValueRegex = SuperExpressive() .between(1, 3).nonDigit .capture .between(1, 3).digit .optional.char(',') .zeroOrMore.group .exactly(3).digit .optional.char(',') .end() .end() .char('.') .exactly(2).digit .optional.group .between(1, 3).nonDigit .end() .toRegex(); const n = '$123,456,789.10'; const matches = n.match(currencyValueRegex); const value = matches ? Number(matches[1].replace(/,/g, '')) : null; // -> value === 123456789 The regex this produces is /\D{1,3}(\d{1,3},?(?:\d{3},?)*)\.\d{2}(?:\D{1,3})?/, and it'll match everything from $1.00 up as far as you can count. It also accounts the fact that sometimes the currency marker is at the end of the number, like in 100.00€ or 1000.00kr. It also uses 2 characters instead of 3 for the currency marker - since stuff like THB or USD is pretty common. More on reddit.com
🌐 r/learnjavascript
6
8
July 14, 2020
How to add currency symbols and locale-based formatting to numbers in JavaScript?
Didn't know Intl handled the currency symbol too. Not sure if that's gonna be reliable though since currency isn't based on language. Plus, this isn't useful. It'd be misleading. You need to convert rates since $100 isn't going to be 100 in whatever other currency. You need an API to get conversion rates, and don't they usually give you currency symbols too? More on reddit.com
🌐 r/learnjavascript
3
1
May 11, 2023
🌐
Justin McCandless
justinmccandless.com › post › formatting-currency-in-javascript
Formatting Currency in Javascript · Justin McCandless
December 13, 2014 - Intl, the new feature available in modern browsers for internationaliztion, is actually really great for localizing and formatting things like currency, but here's to hoping this saves someone time digging through the spec. ... var nf = new Intl.NumberFormat(‘en-US’, { style: ‘currency’, currency: ‘USD’, minimumFractionDigits: 2, maximumFractionDigits: 2 }); nf.format(123456.789); // ‘$123,456.79’
🌐
Embold
blog.embold.io › home › coding › how to format numbers as currency settings in javascript?
How to format numbers as currency settings in JavaScript? – Embold Blog
December 30, 2021 - const canadianCurrencyFormat = new Intl.NumberFormat('en-CAD', { currency: 'CAD' style: 'currency', }). ... nigerianCurrencyFormat.format(1000) //₦1,000.00 canadianCurrencyFormat.format(1000) // 'CA$ 100.00'
🌐
DZone
dzone.com › coding › javascript › how to format a number as currency in javascript
How to Format a Number as Currency in JavaScript
February 7, 2023 - For example, 17225 would be $17,225.00 ... location, and style. You may also use JavaScript's Intl.NumberFormat() function to convert these integers to currencies....
🌐
Codedamn
codedamn.com › news › javascript
How to Format a Number as Currency in JavaScript
June 3, 2023 - The currency option is set to 'USD', which specifies the currency type. Another approach to format numbers as currency is by using template literals and regular expressions.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Intl › NumberFormat › format
Intl.NumberFormat.prototype.format() - JavaScript | MDN
July 10, 2025 - The format() method of Intl.NumberFormat instances formats a number according to the locale and formatting options of this Intl.NumberFormat object. const amount = 654321.987; const options1 = { style: "currency", currency: "RUB" }; const numberFormat1 = new Intl.NumberFormat("ru-RU", options1); console.log(numberFormat1.format(amount)); // Expected output: "654 321,99 ₽" const options2 = { style: "currency", currency: "USD" }; const numberFormat2 = new Intl.NumberFormat("en-US", options2); console.log(numberFormat2.format(amount)); // Expected output: "$654,321.99"
Find elsewhere
🌐
Career Karma
careerkarma.com › blog › javascript › javascript format currency (intl.numberformat)
JavaScript Format Currency (intl.numberformat) | Career Karma
November 10, 2020 - CurrencyDisplay will display the currency in different formatting using values such as symbol, narrowSymbol, code, and name. let money = 85000.50; const symbol = new Intl.NumberFormat('en-USD', { style: 'currency', currency: 'USD', currencyDisplay: ...
🌐
Sentry
sentry.io › sentry answers › javascript › how to format numbers as currency strings
How to format numbers as currency strings | Sentry
March 15, 2023 - Sentry Answers>JavaScript> How ... display to a user. How do you do this? You can create an Intl.NumberFormat object to format a number as a currency string....
🌐
Igniteui
igniteui.com › help › formatting-dates-numbers-and-strings
Formatting Dates, Numbers and Strings - Ignite UI™ Help
In JavaScript: var result = $.ig.formatter(0.55, "number", "0.0"); // result is "0.6" List of supported format specifiers: When type parameter is "string" the $.ig.formatter function parses strings. The {0} placeholder can be used in the format parameter to denote the position of the value parameter in the resulting string.
🌐
Medium
medium.com › @Marioskif › javascript-daily-tips-73-how-to-use-javascripts-intl-numberformat-for-currency-formatting-b8360ac993b5
JavaScript Daily Tips #73: How to Use JavaScript’s Intl.NumberFormat for Currency Formatting | by Mariosdev | Medium
December 13, 2024 - One critical aspect of ... easily understand. JavaScript’s Intl.NumberFormat object is a powerful tool that helps you format numbers, including currencies, for any locale....
🌐
Koladechris
koladechris.com › blog › how-to-format-currencies-in-javascript
JavaScript Format Number as Currency – How to Format Currencies in JavaScript
This approach is still not sustainable because it requires custom logic for different locales and currencies, making it complex and error-prone. There’s a solution, though. That solution is the Intl.NumberFormat object of the JavaScript Internationalization API. ... Subscribe to my newsletter for coding tips, videos from reputable sources, articles from OG tech authors, and a ton of other goodies. No BS. No fluff. Just pure software development goodies on a Sunday every week. Now unto how to format currencies with the Intl.NumberFormat object…
🌐
SamanthaMing
samanthaming.com › tidbits › 30-how-to-format-currency-in-es6
How to Format Currency in ES6 | SamanthaMing.com
const money = 10000; new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR', }).format(money); // '€ 10,000.00' new Intl.NumberFormat('jp-JP', { style: 'currency', currency: 'JPY', }).format(money); // 'JP¥ 10,000' new Intl.NumberFormat('zh-CN', { style: 'currency', currency: 'CNY', }).format(money); // 'CN¥ 10,000.00'
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Intl › NumberFormat › formatToParts
Intl.NumberFormat.prototype.formatToParts() - JavaScript | MDN
The formatToParts() method of Intl.NumberFormat instances returns an array of objects representing each part of the formatted string that would be returned by format(). It is useful for building custom strings from the locale-specific tokens. const amount = 654321.987; const options = { style: "currency", currency: "USD" }; const numberFormat = new Intl.NumberFormat("en-US", options); const parts = numberFormat.formatToParts(amount); const partValues = parts.map((p) => p.value); console.log(partValues); // Expected output: "["$", "654", ",", "321", ".", "99"]" js ·
🌐
JetRockets
jetrockets.com › blog › sypnswfg5k-how-to-display-numbers-with-currency-formatting-in-js
How to display numbers with currency formatting in JS?
February 20, 2019 - const toCurrency = (n, curr, LanguageFormat = undefined) => Intl.NumberFormat(LanguageFormat, { style: 'currency', currency: curr }).format(n);
🌐
Vultr Docs
docs.vultr.com › javascript › examples › format-numbers-as-currency-strings
JavaScript Program to Format Numbers as Currency Strings | Vultr Docs
December 20, 2024 - This JavaScript code listens for changes in an input field (priceInput), formats the entered value as a US Dollar string, and immediately displays the formatted value in another HTML element (formattedPrice). Allow users to select their preferred currency. Format numbers based on the selected currency dynamically.
Top answer
1 of 16
2859

Intl.NumberFormat

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

// Create our number formatter.
const formatter = new Intl.NumberFormat('en-US', {
  style: 'currency',
  currency: 'USD',

  // These options can be used to round to whole numbers.
  trailingZeroDisplay: 'stripIfInteger'   // This is probably what most people
                                          // want. It will only stop printing
                                          // the fraction when the input
                                          // amount is a round number (int)
                                          // already. If that's not what you
                                          // need, have a look at the options
                                          // below.
  //minimumFractionDigits: 0, // This suffices for whole numbers, but will
                              // print 2500.10 as $2,500.1
  //maximumFractionDigits: 0, // Causes 2500.99 to be printed as $2,501
});

// Use the formatter with the value of an input.
let input = document.getElementById('amount');
input.addEventListener('keyup', e => {
    document.getElementById('result').innerText = formatter.format(e.target.value);
});
input.dispatchEvent(new Event('keyup'));
<label>
    Amount
    <input id="amount" value="2500">
</label>
Result:
<span id="result"></span>

Use undefined in place of the first argument ('en-US' in the example) to use the system locale (the user locale in case the code is running in a browser). Further explanation of the locale code.

Here's a list of the currency codes.

Intl.NumberFormat vs Number.prototype.toLocaleString

A final note comparing this to the older .toLocaleString. They both offer essentially the same functionality. However, toLocaleString in its older incarnations (pre-Intl) does not actually support locales: it uses the system locale. So when debugging old browsers, be sure that you're using the correct version (MDN suggests to check for the existence of Intl). There isn't any need to worry about this at all if you don't care about old browsers or just use the shim.

Also, the performance of both is the same for a single item, but if you have a lot of numbers to format, using Intl.NumberFormat is ~70 times faster. Therefore, it's usually best to use Intl.NumberFormat and instantiate only once per page load. Anyway, here's the equivalent usage of toLocaleString:

console.log((2500).toLocaleString('en-US', {
  style: 'currency',
  currency: 'USD',
})); /* $2,500.00 */

Some notes on browser support and Node.js

  • Browser support is no longer an issue nowadays with 99+% support globally
  • There is a shim to support it on fossilized browsers (like Internet Explorer 8), should you really need to
  • Node.js before v13 only supports en-US out of the box. One solution is to install full-icu, see here for more information
  • Have a look at CanIUse for more information
2 of 16
1973

Number.prototype.toFixed

This solution is compatible with every single major browser:

  const profits = 2489.8237;

  profits.toFixed(3) // Returns 2489.824 (rounds up)
  profits.toFixed(2) // Returns 2489.82
  profits.toFixed(7) // Returns 2489.8237000 (pads the decimals)

All you need is to add the currency symbol (e.g. "$" + profits.toFixed(2)) and you will have your amount in dollars.

Custom function

If you require the use of , between each digit, you can use this function:

function formatMoney(number, decPlaces, decSep, thouSep) {
    decPlaces = isNaN(decPlaces = Math.abs(decPlaces)) ? 2 : decPlaces,
    decSep = typeof decSep === "undefined" ? "." : decSep;
    thouSep = typeof thouSep === "undefined" ? "," : thouSep;
    var sign = number < 0 ? "-" : "";
    var i = String(parseInt(number = Math.abs(Number(number) || 0).toFixed(decPlaces)));
    var j = (j = i.length) > 3 ? j % 3 : 0;

    return sign +
        (j ? i.substr(0, j) + thouSep : "") +
        i.substr(j).replace(/(\decSep{3})(?=\decSep)/g, "$1" + thouSep) +
        (decPlaces ? decSep + Math.abs(number - i).toFixed(decPlaces).slice(2) : "");
}

document.getElementById("b").addEventListener("click", event => {
  document.getElementById("x").innerText = "Result was: " + formatMoney(document.getElementById("d").value);
});
<label>Insert your amount: <input id="d" type="text" placeholder="Cash amount" /></label>
<br />
<button id="b">Get Output</button>
<p id="x">(press button to get output)</p>

Use it like so:

(123456789.12345).formatMoney(2, ".", ",");

If you're always going to use '.' and ',', you can leave them off your method call, and the method will default them for you.

(123456789.12345).formatMoney(2);

If your culture has the two symbols flipped (i.e., Europeans) and you would like to use the defaults, just paste over the following two lines in the formatMoney method:

    d = d == undefined ? "," : d,
    t = t == undefined ? "." : t,

Custom function (ES6)

If you can use modern ECMAScript syntax (i.e., through Babel), you can use this simpler function instead:

function formatMoney(amount, decimalCount = 2, decimal = ".", thousands = ",") {
  try {
    decimalCount = Math.abs(decimalCount);
    decimalCount = isNaN(decimalCount) ? 2 : decimalCount;

    const negativeSign = amount < 0 ? "-" : "";

    let i = parseInt(amount = Math.abs(Number(amount) || 0).toFixed(decimalCount)).toString();
    let j = (i.length > 3) ? i.length % 3 : 0;

    return negativeSign +
      (j ? i.substr(0, j) + thousands : '') +
      i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousands) +
      (decimalCount ? decimal + Math.abs(amount - i).toFixed(decimalCount).slice(2) : "");
  } catch (e) {
    console.log(e)
  }
};

document.getElementById("b").addEventListener("click", event => {
  document.getElementById("x").innerText = "Result was: " + formatMoney(document.getElementById("d").value);
});
<label>Insert your amount: <input id="d" type="text" placeholder="Cash amount" /></label>
<br />
<button id="b">Get Output</button>
<p id="x">(press button to get output)</p>

🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-format-numbers-as-currency-string-in-javascript
How to format numbers as currency string in JavaScript ? - GeeksforGeeks
April 30, 2024 - Example 2: In this example we demonstrates formatting numbers as currency strings in JavaScript, using 'en-IN' for INR currency and 'en-US' for USD, applying Intl.NumberFormat to spans with specific classes.
🌐
Numeraljs
numeraljs.com
Numeral.js
Numeral takes numbers or strings ... var value2 = myNumeral2.value(); // 1000 · Numbers can be formatted to look like currency, percentages, times, or even plain old numbers with decimal places, thousands, and abbreviations....