Mrs. Tini’s price labels: toFixed, toPrecision and toExponential on your own number, what they really print, and what 1.005 becomes at two decimals. An…
Why it matters
toFixed is in prices, averages, percentages and scores. Forget that it returns a string and label + 1 becomes glued text. Rely on its .5 rounding and a money total is a cent off. Know both and the numbers you show are right.
The key idea
toFixed prints a string, and rounds what is stored
Common mistakes
(1).toFixed(2) + 1 gives '1.001', not 2 toFixed always returns a string. Wrap it in Number(...) before counting on, or count with the number and print last.
(1.005).toFixed(2) should be 1.01, but prints 1.00 1.005 is stored as 1.00499…, so toFixed rounds down. For display use Intl.NumberFormat (it rounds as written); for money keep whole cents.
A price shows no thousands separator, only digits toFixed adds no separators or symbol. Use new Intl.NumberFormat('id-ID', { style: 'currency', currency: 'IDR' }).
Try it in this playground
Find a five that goes down 1.005, 2.675 or 1.015 with toFixed(2): behind your 5 the stored digit is a 4.
Pad with zeros: 5 → '5.00' toFixed pads with zeros up to d decimals. Good for price labels.
Print with Intl Intl.NumberFormat rounds as written and gives thousands separators for the language.
toPrecision into an exponent 1234.5 with 3 significant digits: 1.23e+3.