BigDecimal 保留小数位
public class test1_format { public static void main(String[] args) { BigDecimal decimal = new BigDecimal("1.12345"); System.out.println(decimal); BigDecimal setScale = decimal.setScale(4,BigDecimal.ROUND_HALF_DOWN); System.out.println(setScale); BigDecimal setScale1 = decimal.setScale(4,BigDecimal.ROUND_HALF_UP); System.out.println(setScale1); } } 参数定义 ROUND_CEILING Rounding mode to round towards positive infinity. 向正无穷方向舍入 ROUND_DOWN Rounding mode to round towards zero. 向零方向舍入 ROUND_FLOOR Rounding mode to round towards negative infinity. 向负无穷方向舍入 ROUND_HALF_DOWN Rounding mode to round towards