var w = 0; var w...">

Adding a Javascript Float

Possible duplicate:
Is JavaScript math broken?

<html>
<body>

<script type="text/javascript">
 var w = 0;
 var weight1 = parseFloat("0.6");
 var weight2 = parseFloat("0.3");
 w = weight1 + weight2;

 document.write("total weight: " + w);
</script>

</body>
</html>

Why is this seal 0.8999999999999999, not 0.90000000

+3
source share
5 answers

Since the number 9/10 cannot be represented purely in base 2, just like the number 1/3 cannot be represented purely in base 10.

+4
source

. . . . (my_float == 3.0) .

0
source

To answer your question, floating points have the same accuracy as your RAM allows. If you create floating point 1, it could be 1.000000000000000000001

Obviously your solutions include rounding a number or using ints

-1
source

Source: https://habr.com/ru/post/1774621/


All Articles