Skip to content
Advertisement

how to make var return 0.00 instead of NaN?

Im working on a price calculator at the moment but in the var proapp2 it will show NaN when the pro app Benutzer slider is 0 how can i make it show 0.00 instead of NaN? i tried if (isNaN(proapp2)) proapp2 = 0.00; but it didnt work?What am i doing wrong?Also i want it to return 0.00 instead of 0.i tried var proapp2 = proapp2 | 0; as well.

JavaScript
JavaScript

Advertisement

Answer

Thi is happening because of a divide by zero. Just change 1 line to have a ternary operator checking if the value you’re dividing by is greater than zero:

JavaScript

You can also get rid of this line

JavaScript

Updated below.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement