java BigDecimal 四舍五入

public static void main(String[] args) {
        BigDecimal strBD=new BigDecimal("1.2345");
        BigDecimal doubleBD=new BigDecimal(1.2345);
        System.out.printf("strBD:%s,\nROUND_HALF_UP:%s\n",strBD,strBD.setScale(3,BigDecimal.ROUND_HALF_UP));
        System.out.printf("doubleBD:%s,\nROUND_HALF_UP:%s\n",doubleBD,doubleBD.setScale(3,BigDecimal.ROUND_HALF_UP));
    }

 

"C:\Program Files\Java\jdk1.8.0_121\bin\java"
strBD:1.2345,
ROUND_HALF_UP:1.235
doubleBD:1.2344999999999999307220832633902318775653839111328125,
ROUND_HALF_UP:1.234

 

posted on 2019-07-09 15:24  Lv Jianwei  阅读(...)  评论(...编辑  收藏

统计