Creating a NumberFormat Instance
What you'll learn: How to create an Intl.NumberFormat object using its constructor, including the locales and options parameters.
Now that you know what Intl.NumberFormat does, let's see how to actually create one. The constructor follows a standard pattern used throughout the Intl API.
The Constructor Signature
The basic syntax is:
new Intl.NumberFormat(locales, options)
Both parameters are optional, but they give you fine-grained control over formatting.
The locales Parameter
This is a string (or array of strings) representing language/region codes like 'en-US', 'fr-FR', or 'ja-JP'. It tells the formatter which locale's conventions to use:
const usFormatter = new Intl.NumberFormat('en-US');
const germanFormatter = new Intl.NumberFormat('de-DE');
If you omit it, JavaScript uses the runtime's default locale (usually your system settings).
The options Parameter
This object lets you customize formatting behavior—things like decimal places, currency display, or grouping separators. Common options include style, currency, minimumFractionDigits, and more (you'll explore these in detail soon):
const currencyFormatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD'
});
Creating Without Arguments
The simplest instance uses all defaults:
const defaultFormatter = new Intl.NumberFormat();
This works perfectly when you just want locale-aware formatting without customization.
Key Takeaway: Create a NumberFormat instance with new Intl.NumberFormat(locales, options)—both parameters are optional, giving you a spectrum from "use all defaults" to "precise control over every formatting detail."