public static void main(String[] args){ float a = (float) 1.0; float b = (float) 0.965; double a1 = 1.0; double b1 = 0.965; BigDecimal a2 = new BigDecimal(a1); BigDecimal b2 = new BigDecimal(b1); BigDecimal a3 = new BigDecimal(new String("1.0")); BigDecimal b3 = new BigDecimal(new String("0.965")); System.out.println("float:"+(a-b)); System.out.println("double:"+(a1-b1)); System.out.println("BigDecimal use Double:"+a2.subtract(b2)); System.out.println("BigDecimal use String:"+a3.subtract(b3)); }
float:0.035000026
double:0.03500000000000003
BigDecimal use Double:0.03500000000000003108624468950438313186168670654296875
BigDecimal use String:0.035
标签:use,动脑,BigDecimal,float,动手,课后,new,out,String From: https://www.cnblogs.com/kongxiangzeng/p/17707147.html