Double: compare(double d1, double d2) : Double « java.lang « Java by API






Double: compare(double d1, double d2)

  


public class Main {

  public static void main(String[] args) {
    double d1 = 5.5;
    double d2 = 5.4;
    int i1 = Double.compare(d1, d2);
    if (i1 > 0) {
      System.out.println(">");
    } else if (i1 < 0) {
      System.out.println("<");
    } else {
      System.out.println("=");
    }
    Double dObj1 = new Double("5.5");
    Double dObj2 = new Double("5.4");
    int i2 = dObj1.compareTo(dObj2);
    if (i2 > 0) {
      System.out.println(">");
    } else if (i2 < 0) {
      System.out.println("<");
    } else {
      System.out.println("=");
    }
  }
}

   
    
  








Related examples in the same category

1.Double.MAX_VALUE
2.Double.MIN_VALUE
3.Double.NEGATIVE_INFINITY
4.Double.POSITIVE_INFINITY
5.new Double(double value)
6.new Double(String stringValue) '314159E-5'
7.Double: byteValue()
8.Double: compareTo(Double anotherDouble)
9.Double: doubleValue()
10.Double: equals
11.Double: floatValue()
12.Double: intValue()
13.Double: isInfinite()
14.Double: isNaN()
15.Double: parseDouble(String s)
16.Double: shortValue()
17.Double: toString(double d)
18.Double: valueOf(String stringValue)