关于String类型,转换BigDecimal .并且BigDecimal 的乘法计算
//减法计算
BigDecimal insuranceAmt= BigDecimal.ZERO;
BigDecimal price_JQX = BigDecimal.ZERO;
BigDecimal price = insuranceAmt.subtract(price_JQX);
//乘法计算,保留两位小数,只舍去不入
1 BigDecimal price_bonus = price.multiply(new BigDecimal(0.94,new MathContext(2))).setScale(2, BigDecimal.ROUND_DOWN);
//加法运算
public static double add(double v1, double v2) { BigDecimal b1 = new BigDecimal(Double.toString(v1)); BigDecimal b2 = new BigDecimal(Double.toString(v2)); return b1.add(b2).doubleValue(); }
//字符串与BigDecimal的相互转换
BigDecimal b = new BigDecimal(columnValue);
//变成金钱格式,留 .0 DecimalFormat format = new DecimalFormat("0.0"); String floatString = format.format(b);
//String 转换 BigDecimal
String a = "1.1"; //字符串类型,必须是数字,否则会报错, java.lang.NumberFormatException 异常
System.out.println(new BigDecimal(a));