小编Geo*_*ier的帖子

Strange rounding issue with BigDecimal

Note this is not a duplicate, I'm and referring to rounding; not adding.

So I am dealing with BigDecimal and everything I do works as planned except for the rounding of certain numbers. It is easier to explain with code, but the rounding changes property between numbers. Note this is a always round down mode (truncating). It should round to 6 numbers in the decimal point.

    System.out.println( (new BigDecimal(1.340)).round(new MathContext(7, RoundingMode.DOWN))); //returns 1.400000
    System.out.println( (new BigDecimal(2.340)).round(new MathContext(7, RoundingMode.DOWN))); //returns 2.339999 …
Run Code Online (Sandbox Code Playgroud)

java rounding bigdecimal

0
推荐指数
1
解决办法
43
查看次数

标签 统计

bigdecimal ×1

java ×1

rounding ×1