//初始化1000.155
BigDecimal bigDecimal = new BigDecimal(1000.155);
//直接舍去小数点后2两位
bigDecimal=bigDecimal.setScale(2,BigDecimal.ROUND_DOWN);
System.out.println(bigDecimal);//1000.15
//去除小数,向上进位
bigDecimal = bigDecimal.setScale(0,BigDecimal.ROUND_UP);
System.out.println(bigDecimal);//1001
//四舍五入
bigDecimal = bigDecimal.setScale(0,BigDecimal.ROUND_HALF_UP);
System.out.println(bigDecimal);//1001
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/tech/opensource/196004.html