Reputation: 13
I am trying the below code but after executing 344741.79
value is showing as 344741.78
Means after decimal place .79
is getting converted to .78
, I am really wondering why I am not getting the exactly same value after conversion and which logic is doing this?
public static void main(String[] s) {
double a = 344741.79;
System.out.print(new Float(a));
}
Upvotes: 1
Views: 54
Reputation: 7874
Float
is only guaranteed to accurately store 6 significant decimal digits. In the case of 344741.79, the 2 nearest Float
s are 344741.78125 (which is printed as 344741.78
) and 344741.8125 (which is printed as 344741.8
).
Upvotes: 1