Compare two double values
static int compare(double d1, double d2)
- Compares the two specified double values.
int compareTo(Double anotherDouble)
- Compares two Double objects numerically.
boolean equals(Object obj)
- Compares this object against the specified object.
static int compare(double d1, double d2) and int compareTo(Double anotherDouble) have the same returns:
Value | Meaning |
---|---|
0 | if anotherDouble is numerically equal to this Double |
less than 0 | if this Double is numerically less than anotherDouble; |
value greater than 0 | if this Double is numerically greater than anotherDouble. |
public class Main {
public static void main(String[] args) {
Double double1 = new Double(1.1);
Double double2 = new Double("1.2");
System.out.println(double1.compareTo(double2));
}
}
The output:
-1
public class Main {
public static void main(String[] args) {
Double double1 = new Double(1.1);
Double double2 = new Double("1.2");
System.out.println(Double.compare(double1,double2));
}
}
The output:
-1
Home
Java Book
Essential Classes
Java Book
Essential Classes
Double:
- Double class
- Constants in Double class
- Double class Constructor
- Return double value as byte, double, float, int, long, short
- Compare two double values
- Is a double value an infinite large value, or it is not a number.
- Convert string value to double
- Convert double value from string
- Get the hexadecimal string representation
- Bit oriented calculation for double type