How to make floating point arithmetic accurate in JavaScript

1 Answer

0 votes
<script>
var x = 0.1 + 0.2;
document.write(x + "<br />");

var y = (0.1 * 10 + 0.2 * 10) / 10;
document.write(y + "<br />");
 
/*
run:
 
0.30000000000000004
0.3
 
*/
</script>

 



answered Sep 2, 2016 by avibootz
...