From http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#189955:
Java can lose precision without compile-time or run-time error:
Despite the fact that loss of precision may occur, widening conversions among primitive types never result in a run-time
exception (?11).
Here is an example of a widening conversion that loses precision:
class Test {
public static void main(String[] args) {
int big = 1234567890;
float approx = big;
System.out.println(big - (int)approx);
}
}
which prints:
-46
thus indicating that information was lost during the conversion from type int to type float because values of type float are
not precise to nine significant digits.
|
java
|
9/16/2002 12:17 AM
jcohen
|
New Window
Move/Edit
|