Also written as format currency
Formatting Decimals
JS · Numbers & Mathsyntax
num.toFixed(digits)
num.toPrecision(precision)
example
const total = 29.5;
console.log(total.toFixed(2));
console.log((0.1 + 0.2).toFixed(2));
const big = 123456.789;
console.log(big.toPrecision(6));
Note toFixed() returns a STRING, not a number. Wrap in Number() or use + to convert back: +total.toFixed(2)
Locale Number Formatting
JS · Numbers & Mathsyntax
new Intl.NumberFormat(locale, options).format(n)
example
const price = 1234567.89;
console.log(new Intl.NumberFormat("en-US", {
style: "currency", currency: "USD"
}).format(price));
console.log(new Intl.NumberFormat("de-DE").format(price));
Note Intl.NumberFormat handles thousands separators, currency symbols, percentages, and units correctly for any locale.