比较 BigDecimal 是否大于零

Compare if BigDecimal is greater than zero(比较 BigDecimal 是否大于零)

本文介绍了比较 BigDecimal 是否大于零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

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.

这篇关于比较 BigDecimal 是否大于零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:比较 BigDecimal 是否大于零

基础教程推荐