This is because floating point arithmetic! = Real number arithmetic .
When f is assigned 2000000000 , it is converted to 2.0E9 . Then, when you add 50 to 2.0E9 , its value does not change. So (f == temp + 50) true .
If you need to work with large numbers, but you need precision, you will need to use something like BigDecimal :
long temp = 2000000000; BigDecimal d = new BigDecimal(temp); System.out.println(d.compareTo(new BigDecimal(temp+50)) < 0);
true will be printed as expected.
(although in your case I don't know why you need to use a data type other than long ).
source share