minor fixes
This commit is contained in:
parent
6edb240b48
commit
741d90ce8a
1 changed files with 2 additions and 2 deletions
|
@ -213,13 +213,13 @@ Strange! What is it then if not `0.3`?
|
|||
alert( 0.1 + 0.2 ); // 0.30000000000000004
|
||||
```
|
||||
|
||||
Ouch! There are more consequences than an incorrect comparison here. Imagine you're making an e-shopping site and the visitor puts `$0.10` and `$0.20` goods into their cart. The order total will be `$0.30000000000000004`. That would surprise anyone.
|
||||
Ouch! Imagine you're making an e-shopping site and the visitor puts `$0.10` and `$0.20` goods into their cart. The order total will be `$0.30000000000000004`. That would surprise anyone.
|
||||
|
||||
But why does this happen?
|
||||
|
||||
A number is stored in memory in its binary form, a sequence of bits - ones and zeroes. But fractions like `0.1`, `0.2` that look simple in the decimal numeric system are actually unending fractions in their binary form.
|
||||
|
||||
In other words, what is `0.1`? It is one divided by ten `1/10`, one-tenth. In decimal numeral system such numbers are easily representable. Compare it to one-third: `1/3`. It becomes an endless fraction `0.33333(3)`.
|
||||
What is `0.1`? It is one divided by ten `1/10`, one-tenth. In decimal numeral system such numbers are easily representable. Compare it to one-third: `1/3`. It becomes an endless fraction `0.33333(3)`.
|
||||
|
||||
So, division by powers `10` is guaranteed to work well in the decimal system, but division by `3` is not. For the same reason, in the binary numeral system, the division by powers of `2` is guaranteed to work, but `1/10` becomes an endless binary fraction.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue