JavaScript

Format currency with Intl.NumberFormat

Use Intl.NumberFormat with an explicit locale and currency to display monetary amounts. The formatter chooses currency symbols, separators, and default fraction digits appropriate to those settings.

Worked example

Node.js example · save as example.mjs and run node example.mjs

const format = new Intl.NumberFormat("en-CA", {
  style: "currency", currency: "CAD"
});
console.log(format.format(1234.5));

How it works

Create the formatter once when displaying many amounts. Currency identifies the unit being presented; it does not convert one currency into another. The input remains a number in the chosen unit, so pass 1234.5 dollars rather than an unconverted cent total.

Limits and mistakes

Formatting does not make binary floating-point arithmetic exact and does not fetch exchange rates. Spaces and symbols can vary with locale data. Do not parse the formatted string back into a number by stripping punctuation.

Check the result

Confirm that the result represents 1,234.50 Canadian dollars. For automated checks that must tolerate locale spacing differences, inspect formatToParts rather than hardcoding the complete display string.

Sources

Reference documentation for the behavior used in this guide: