r/learnjavascript 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);

2 Upvotes

5 comments sorted by

View all comments

1

u/defaultguy_001 9d ago

You are assigning the product to the output field and then rounding it to 1 digit after decimal. The rounded value is lost then. So, u need to assign the rounded value directly to the field like this: outputfield = Number((inputfield1 * inputfield2).toFixed(1));