java double方法
双类compare()方法 (Double class compare() method)
- compare() method is available in java.lang package. - compare()方法在java.lang包中可用。 
- compare() method is used to check equality or inequality of the given two double values or in other words, we can say this method is used to compare two double values. - compare()方法用于检查给定两个双精度值的相等或不相等,换句话说,可以说此方法用于比较两个双精度值。 
- compare() method is a static method, it is accessible with the class name too and if we try to access the method with the class object then also, we will not get an error. - compare()方法是一个静态方法,它也可以使用类名进行访问,如果我们尝试使用类对象访问该方法,那么也不会出错。 
- compare() method does not throw an exception at the time of comparing double values. - 比较双精度值时, compare()方法不会引发异常。 
Syntax:
句法:
    public static int compare(double value1, double value2);
Parameter(s):
参数:
- double value1, double value2 – These parameters represent the double values to be compared. - double value1,double value2 –这些参数表示要比较的double值。 
Return value:
返回值:
The return type of this method is int, it returns an integer value.
此方法的返回类型为int ,它返回一个整数值。
- In the first case, it returns 0 if value1 is mathematically equals to value2. - 在第一种情况下,如果value1在数学上等于value2 ,则它返回0 。 
- In the second case, it returns the value < 0 if value1 is mathematically less than value2. - 在第二种情况下,如果value1在数学上小于value2 ,则它返回值<0 。 
- In the third case, it returns the value > 0 if value1 is mathematically greater than value2. - 在第三种情况下,如果value1在数学上大于value2 ,则它返回> 0的 值 。 
Example:
例:
// Java program to demonstrate the example 
// of compare(double value1,double value2) 
// method of Double class
public class CompareOfDoubleClass {
public static void main(String[] args) {
// Variables initialization
double value1 = 18.20;
double value2 = 20.20;
// It compares two double values and 
// returns the result in another variable (compare) 
// of integer types
int compare = Double.compare(value1, value2);
// Display result
System.out.println("Double.compare(value1,value2): " + compare);
System.out.println();
if (compare == 0)
System.out.println("value1 is equal to value2");
else if (compare < 0)
System.out.println("value1 is less than value2");
else
System.out.println("value1 is greater than value2");
}
}
Output
输出量
Double.compare(value1,value2): -1value1 is less than value2
翻译自: https://www.includehelp.com/java/double-class-compare-method-with-example.aspx
java double方法