Let us try the same thing in a different language:
So obviously this is not equal to 0.3
Right way to do it : Using BigDecimal
If you tried the same in Python, you will still get the same unexpected result.
Using the toFixed function from Number object helps us in setting the number of digits after the decimal point.It returns a string and hence we need the + operator at the beginning.
But why is 0.1 + 0.2 ! = 0.3, take a look here : Floating point Math