Reputation: 39
the value of the name is 115.5
, but when I run the below code, I get 115
. Why? I thought Math.round()
rounded up at .5
. Please help.
Math.round(parseInt(document.getElementsByName("prod_Unit_Price_1")[0].value)));
Upvotes: 1
Views: 50
Reputation: 2485
An integer doesn't have a decimal place. When you parseInt()
you strip out the decimal. Use parseFloat()
instead
Math.round(parseFloat(document.getElementsByName("prod_Unit_Price_1")[0].value)));
Upvotes: 4