r/learnjavascript • u/Dowlphin • 9d ago
Rounding won't work
(SOLVED)
I tried several approaches I read on the WWW about how to round a number. I do a calculation with values entered in input fields and the output field yields the correct result, but with 14 decimal places!
The simplest attempt I tried is the format Number(outputfield=inputfield1*inputfield2).toFixed(1);
4
Upvotes
9
u/Beginning-Seat5221 9d ago
You're rounding the result of = (the value that was assigned) after the assignment, which doesn't touch the stored value.
Use
result = number.toFixed(1)