Name: sg39081 Date: 10/16/97
double x = 1.0e+19
double answer = java.lang.Math.round(x);
bug: answer is -9.2233720368548e+018
If x is 1.0e+18, round() returns correct answer''
public class round
{
public static void main( String[]args)
{
double x = 1.0e+19;
double answer = java.lang.Math.round(x);
System.out.println("x=" + x);
System.out.println("answer=" + answer);
x = 1.0e+18;
answer = java.lang.Math.round(x);
System.out.println("x=" + x);
System.out.println("answer=" + answer);
}
}
======================================================================
- duplicates
-
JDK-1229191 (math) Converting floating-point numbers to ints doesn't always work properly
- Closed