1、直接用Double对象判断得到的是不相等
public static void main(String[] args) { try { Double d = new Double("1"); Double d1 = new Double("1"); if(d != d1) { System.out.println("d != d1"); } System.out.println("d = d1"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
输出:d != d1
2、转成double 去判断得到的是相等(或者Double对象的toString()方法去判断也是没有问题的)
public static void main(String[] args) { try { Double d = new Double("1"); Double d1 = new Double("1"); if(d.doubleValue() != d1.doubleValue()) { System.out.println("d != d1"); }else { System.out.println("d = d1"); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
输出:d = d1
标签:相等,Double,System,判断,catch,new,d1,out From: https://www.cnblogs.com/wwssgg/p/17192342.html