0.1+0.2 === 0.3 // output: false | Sololearn: Learn to code for FREE!


0.1+0.2 === 0.3 // output: false

Very interesting. I tried on JavaScript but something went wrong. 0.1+0.2=0.30000000004 what? really? I so confused. Why result show me wrong answer?

5/17/2021 1:00:50 AM

Chingun Undrakh

9 Answers

New Answer


This is an action of the accuracy of the calculations. When JavaScript performs calculations, it converts the values to binary equivalents. And here there is a problem, since 0.1 can not be exactly represented in the binary equivalent, which is used for binary floating-point operations. In order to overcome this incident, there are two methods (the choice is yours): 1. Convert values to integers, calculate, and then reverse convert to decimals. 2. building the logic so that it works with a range of numbers, not an exact value.


other oddities: null is an object, NaN is a number, array without keys == false //Answer: true


floating point arithmetic is not always 100% accurate. To solve this type of problem you can use (0.1*10 + 0.2*10) / 10


Vansh Kaushik please can you create different threads to ask your question So no one would get confused


The accuracy of calculating is so bad for decimal number, I also have the same problem when working on my python calculator


How i make program if i write hello he say hello vansh


Vansh Kaushik πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”


When i am running my calculator on JS, I have the same problem.