System.out.print(819389.98+6.44);
为啥是等于819396.4199999999要怎么解决

解决方案 »

  1.   

    浮点数计算的时候是存在误差的,可以使用BigDecimal类来取代
      

  2.   

    DecimalFormat df = new DecimalFormat("#0.00");
    System.out.print(Double.parseDouble(df.format(819389.98 + 6.44)));
      

  3.   

    DecimalFormat df = new DecimalFormat("#0.00");
    System.out.print(Double.parseDouble(df.format(819389.98 + 6.44)));
    这样可以解决,最好还是用BigDecimal来替代你的数据类型