Check if BigDecimal is integer value

前端 未结 7 2149
有刺的猬
有刺的猬 2021-02-03 17:36

Can anyone recommend an efficient way of determining whether a BigDecimal is an integer value in the mathematical sense?

At present I have

相关标签:
7条回答
  • 2021-02-03 18:03

    This is the cleanest I've come up with.

    public static boolean isWhole(BigDecimal bigDecimal) {
        return bigDecimal.setScale(0, RoundingMode.HALF_UP).compareTo(bigDecimal) == 0;
    }
    
    0 讨论(0)
提交回复
热议问题