Compare two float values with Float.floatToIntBits in Java
Description
The following code shows how to compare two float values with Float.floatToIntBits.
Example
/*ww w .j a v a2 s. co m*/
public class Main {
public static boolean areEqual(float aThis, float aThat) {
// System.out.println("float");
return Float.floatToIntBits(aThis) == Float.floatToIntBits(aThat);
}
public static void main(String[] argv) {
System.out.println(areEqual(0.1f, 0.2f));
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »