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
ago 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
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)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...