You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/05-data-types/02-number/article.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -213,13 +213,13 @@ Strange! What is it then if not `0.3`?
213
213
alert( 0.1 + 0.2 ); // 0.30000000000000004
214
214
```
215
215
216
-
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.
216
+
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.
217
217
218
218
But why does this happen?
219
219
220
220
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.
221
221
222
-
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)`.
222
+
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)`.
223
223
224
224
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.
0 commit comments