集册 Java实例教程 比较双精度值

比较双精度值

—— 比较双值

欢马劈雪     最近更新时间:2020-01-02 10:19:05

454
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
比较双值
/*来 自 时 代 J a v a - N o w J a v a . c o m*/

 

public class Main {

 

  public static void main(String[] args) {

    double d1 = 5.35;

    double d2 = 5.34;

    int i1 = Double.compare(d1,d2);

   

    if(i1 > 0){

      System.out.println("First is greater");

    }else if(i1 < 0){

      System.out.println("Second is greater");

    }else{

      System.out.println("Both are equal");

    }

   

    Double dObj1 = new Double("5.35");/** nowjava.com 提 供 **/

    Double dObj2 = new Double("5.34");

    int i2 = dObj1.compareTo(dObj2);

   

    if(i2 > 0){

      System.out.println("First is greater");

    }else 
展开阅读全文