Float: compare(float f1, float f2) : Float « java.lang « Java by API






Float: compare(float f1, float f2)

  

public class Main {

  public static void main(String[] args) {
    float f1 = 5.5f;
    float f2 = 5.4f;
    int i1 = Float.compare(f1, f2);
    if (i1 > 0) {
      System.out.println(">");
    } else if (i1 < 0) {
      System.out.println("<");
    } else {
      System.out.println("=");
    }

    Float fObj1 = new Float("5.5");
    Float fObj2 = new Float("5.4");
    int i2 = fObj1.compareTo(fObj2);
    if (i2 > 0) {
      System.out.println(">");
    } else if (i2 < 0) {
      System.out.println("<");
    } else {
      System.out.println("=");
    }
  }
}

   
    
  








Related examples in the same category

1.Float.MAX_VALUE
2.Float.MIN_VALUE
3.new Float(String s)
4.new Float(float value)
5.Float: byteValue()
6.Float: floatValue()
7.Float: compareTo(Float anotherFloat)
8.Float: doubleValue()
9.Float: intValue()
10.Float: isInfinite(float v)
11.Float.isNaN() Returns true if this Float value is a Not-a-Number (NaN),
12.Float: parseFloat(String s)
13.Float: shortValue()
14.Float: toString()
15.Float: toString(float f)
16.Float: valueOf(String stringValue)