Decimals in JavaScript April 30th, 2013
Use decimals cautiously because JavaScript uses Binary Floating Point numbers, so 0.1 + 0.2 = 0.30000000000000004. To get around this issue, you can multiply your numbers to remove the decimal portion.
var hamburger = 8.20; var fries = 2.10; var total = hamburger + fries; console.log(total); //Outputs 10.299999999999999 hamburger = hamburger * 100; fries = fries * 100; total = hamburger + fries; total = total / 100; console.log(total); //Outputs 10.3