Compare if BigDecimal is greater than zero

后端 未结 7 2019
既然无缘
既然无缘 2020-12-22 21:23

How can I compare if BigDecimal value is greater than zero?

相关标签:
7条回答
  • 2020-12-22 22:11

    It's as simple as:

    if (value.compareTo(BigDecimal.ZERO) > 0)
    

    The documentation for compareTo actually specifies that it will return -1, 0 or 1, but the more general Comparable<T>.compareTo method only guarantees less than zero, zero, or greater than zero for the appropriate three cases - so I typically just stick to that comparison.

    0 讨论(0)
提交回复
热议问题