java中比较double大小

 Double obj1 = new Double("8.5");
     Double obj2 = new Double("11.50");
     int retval =  obj1.compareTo(obj2);
    
     if(retval > 0) {
        System.out.println("obj1 is greater than obj2");
     }
     else if(retval < 0) {
        System.out.println("obj1 is less than obj2");
     }
     else {
        System.out.println("obj1 is equal to obj2");
     }

你可能感兴趣的:(java基础)