如何根据小数舍入为数字设置通用缩放
BigDecimal num = new BigDecimal(25) BigDecimal result = num.divide(new BigDecimal(13), 7, RoundingMode.HALF_EVEN) // 1.9230769
但
BigDecimal result = num.divide(new BigDecimal(10), 7, RoundingMode.HALF_EVEN) // 2.5000000 that should be 2.5
大概分析余数?
API中是否有针对此类情况的内容?
看一下https://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html#stripTrailingZeros--
BigDecimal bd = new BigDecimal("235.000"); System.out.println( bd.stripTrailingZeros() );