比较BigDecimal是否大于零 [英] Compare if BigDecimal is greater than zero

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

问题描述

如果BigDecimal值大于零,如何比较?

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

推荐答案

它很简单:

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

compareTo 的文档实际上指定它将返回-1、0或1,但是更通用的Comparable<T>.compareTo方法仅保证在适当的三种情况下小于零,零或大于零-所以我通常只是坚持比较.

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是否大于零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆