Back
I have the following code in Java;
BigDecimal price; // assigned elsewhereif (price.compareTo(new BigDecimal("0.00")) == 0) { return true;}
BigDecimal price; // assigned elsewhere
if (price.compareTo(new BigDecimal("0.00")) == 0) {
return true;
}
What is the best way to write the if condition?
Try, signum() can be used:
if (price.signum() == 0) { return true;}
if (price.signum() == 0) {
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)
{
1.2k questions
2.7k answers
501 comments
693 users