Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (3.9k points)
How can I compare if BigDecimal value is greater than zero?

1 Answer

0 votes
by (46k points)

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.

Related questions

0 votes
2 answers
0 votes
1 answer
0 votes
1 answer
0 votes
2 answers
asked Nov 25, 2019 in Java by Anvi (10.2k points)

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...