Intellipaat 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?

2 Answers

0 votes
by (46k points)

Try, signum() can be used:

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

    return true;

}

0 votes
by (1.8k points)

We can cross verify whether big decimal variable value is equal to zero in java by following code:

BigDecimal price;

If ( price.compareTo(new BigDecimal(“0.00”)) == 0)

{

return true;

}

Related questions

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

...