Formats a number to a fixed number of decimal places as a string.
This function wraps Number.toFixed() to convert a number into a string with the specified number of decimal places.
Number.toFixed()
Note: The result is always a string. It rounds the number as needed.
The number to format.
The number of decimal places to include.
The formatted number as a string.
formatNumber(1.2345, 2); // "1.23"formatNumber(1, 2); // "1.00"formatNumber(0.1 + 0.2, 2); // "0.30" Copy
formatNumber(1.2345, 2); // "1.23"formatNumber(1, 2); // "1.00"formatNumber(0.1 + 0.2, 2); // "0.30"
Formats a number to a fixed number of decimal places as a string.
This function wraps
Number.toFixed()
to convert a number into a string with the specified number of decimal places.Note: The result is always a string. It rounds the number as needed.