We're going to have a situation when we multiply in JS.
<input type= "text" id= "NUM1" value= ""/>*<input type= "text" id= "num2" value= ""/> <input type= "button" id= "TT" value= "="/> <input id= "result" type= "text" value= ""/>
$ (function () {$ ("#tt"). Click (function () {var num1=$ ("#num1"). Val (); var num2=$ ("#num2"). Val (); var result=num1*num2;$ ("#result"). Val (result);});
Results:
The correct result is 30.8.
At this point we should use tofixed (num)
Description: The parameter num is required. Specifies the number of digits rounded to a decimal, which is a value between 0 and 20, including 0 and 20, and some implementations can support a larger range of values. If this argument is omitted, 0 will be used instead .
$ (function () {$ ("#tt"). Click (function () {var num1=$ ("#num1"). Val (); var num2=$ ("#num2"). Val (); var result=num1*num2;$ ("#result"). Val (result.tofixed (1));});
JavaScript toFixed Usage