First question: In java script if we do.
0.2 + 0.1
=>0.30000000000000004
Because 0.2,0.1 are rounded off to different number and also the sum is rounded of to a different number This article explains the behind the scenes.I understand this but when i do.
0.3 + 0
=>0.3
It shows 0.3 why? 0.3 cannot be exactly represented in binary right and it should be rounded to different number right?.
so the value of 0.3 + 0 should be the rounded number of 0.3 and the sum if needed?.
Second question:
when we do.
let x = 0.3
As 0.3 cannot be represented exactly in binary it is rounded of to another number but when you access the variable x why does it show 0.3 but not the actual rounded of number.
x
=>0.3
But when you do.
0.2 + 0.1
=>0.30000000000000004
It shows the actual rounded of number but not 0.3. Kindly explain.