Check if BigDecimal is integer value

前端 未结 7 2145
有刺的猬
有刺的猬 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 17:45

    You can use this (just summarizing from other answers):

    private boolean isIntegerValue(BigDecimal bd) {
      return bd.stripTrailingZeros().scale() <= 0;
    }
    

提交回复
热议问题