# float result

Vishnu Prakash
Ranch Hand
Posts: 1026

o/p ==> -46

Ravi Shankar R
Greenhorn
Posts: 7
when the value of int i is assigned to float f the value of f is 1.234567936E9 since the change has happened from an integer literal to double literal so i = 1234567890 and f = 1.234567936E9

thus, i - f = 1234567890 - 1.234567936E9 = -46

Rupak Khurana
Ranch Hand
Posts: 89
How did you come up with f = 1.234567936E9 ?

Jay Pawar
Ranch Hand
Posts: 411
Originally posted by vishnu prakash:

o/p ==> -46

System.out.println(i - (int)f);
when you cast the float value f to int the resultant value is 1234567936
hence the value printed out is ( 1234567890 - 1234567936 ) which is -46

Greenhorn
Posts: 3
First, sorry for my serious bad inglish, but i'm tring.

The question is: why 1234567890 when converting to float is 1.234567936E9 ???

Steven Bell
Ranch Hand
Posts: 1071
Floating point values are not accurate. Do a search on this forum for floating point accuracy, it has been discussed many times.