What will this statement return 3*0.1 == 0.3? true or false?

By | August 22, 2019

In this post we will discuss about one of the basic  java interview question and question is that What will this statement return 3*0.1 == 0.3? true or false?

This is one of the really most tricky interview question in java. Only few developers answer this question and explain the concept correctly. The very short and crispy answer is false because some floating-point numbers cannot be represented exactly.

Let’s understand above concept using an example

Sample Output

d1 = 0.30000000000000004
d2 = 0.3
d3 = 100.0
d4 = 100.0

You may also like:

Why should I choose Java for Software Development? What are Pros and Cons of Java?
Can we cast an int value into byte type variable? what if the value of int is larger than byte?
Can We store a double value in a long type variable without casting?
Why Java is not 100% Object-oriented language?
What are the differences between 32-bit and 64-bit versions of Java?
Can we call static method with null object?

Thanks for visiting our blog.
If you have any feedback or suggestion please feel free to drop in blow comment box. 

Leave a Reply

Your email address will not be published. Required fields are marked *