Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (10.2k points)

I have the following code in Java;

BigDecimal price; // assigned elsewhere

if (price.compareTo(new BigDecimal("0.00")) == 0) {

    return true;

}

What is the best way to write the if condition?

1 Answer

0 votes
by (46k points)

Try, signum() can be used:

if (price.signum() == 0) {

    return true;

}

Related questions

0 votes
1 answer
0 votes
1 answer
asked Aug 29, 2019 in Java by Ritik (3.5k points)
0 votes
2 answers
asked Jul 9, 2019 in Java by Anvi (10.2k points)

Browse Categories

...