Tuesday, 10 September 2013

how to get exact answer without losing information

how to get exact answer without losing information

class Test {
public static void main(String[] args) {
int big = 1234567890;
float approx = big;
System.out.println(big - (int)approx);
}
}
I got the above code from the Java language specification. My doubt is
there any possible way to get the right answer. I used strictfp but I got
the same result (see the below code):
strictfp class Test6 {
public static void main(String[] args) {
int big = 1234567890;
float approx = big;
System.out.println(big - (int)approx);
}
}
This outputs -46.

No comments:

Post a Comment