The format() method formats the number to a localized string.

Reset
"1,234.56"

The formatToParts() method outputs an array with each part of the number separated by parts. This is useful for determining the properties of a locale, which can be useful for parsing numbers. See the parsing guide.

Reset
[{"type":"integer","value":"1"},{"type":"group","value":","},{"type":"integer","value":"234"},{"type":"decimal","value":"."},{"type":"fraction","value":"56"}]

Changing the numbering system

You can change the numbering system in your locale by adding -u-nu-{code}.

One common example is the Chinese locale of zh that uses latn as the default numbering system:

Reset
"1,234.56"

But hanidec is also very common in this locale, and would look like this:

Reset
"一,二三四.五六"

Another way to change the numbering system is to specify the numberingSystem option.

Reset
"一,二三四.五六"

Number of Decimals Places

By default, decimals are rounded to 3 digits:

Reset
"0.556"

To override the default number of decimal places, use the minimumFractionDigits option:

Reset
"0.55556"

Currency Formatting

To format a number as a currency, you need to set the style and currency options:

Reset
"$12.99"

Percent Formatting

To format a number as a percent, the number should be between 0 and 1, and the style should be set to percent:

Reset
"75%"

Full Intl.NumberFormat API Documentation