Rounding necessary with BigDecimal numbers

前端 未结 3 1766
悲&欢浪女
悲&欢浪女 2021-02-06 21:00

I want to set scale of two BigDecimal numbers a and b . as in this example :

BigDecimal a = new BigDecimal(\"2.6E-1095\");
        BigD         


        
3条回答
  •  猫巷女王i
    2021-02-06 21:53

    You have two BigDecimal numbers both of which require over a 1000 decimal places. Trying to set the scale to only have 113 decimal places means you will lose precision and therefore you need to round.

    You can use the setScale methods that take a RoundingMode to prevent the exception but not the rounding.

提交回复
热议问题