大家好,又见面了,我是你们的朋友全栈君。
BigDecimal n1 = new BigDecimal("0.01");
BigDecimal n2 = new BigDecimal("0.02");
System.out.println("加法:"+n2.add(n1));
加法:0.03
BigDecimal n1 = new BigDecimal("0.01");
BigDecimal n2 = new BigDecimal("0.02");
System.out.println("减法:"+n2.subtract(n1));
减法:0.01
BigDecimal n1 = new BigDecimal("0.01");
BigDecimal n2 = new BigDecimal("0.02");
System.out.println("乘法:"+n2.multiply(n1));
乘法:0.0002
BigDecimal n1 = new BigDecimal("0.01");
BigDecimal n2 = new BigDecimal("0.02");
System.out.println("除法:"+n2.divide(n1));
除法:2
BigDecimal n3 = new BigDecimal("-0.09");
System.out.println("绝对值:"+n3.abs());
绝对值:0.09
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/129567.html原文链接:https://javaforall.cn