I’m looking to calculate if a value of a variable in java is equal to 0.00 which is currently defined as a big decimal .
I have tried a variety of ways to do this including:
tempListPrice.getAmount() == 0.00;
tempListPrice.getAmount().equals(0.00);
public static final zeroed = 0.00
tempListPrice.getAmount().equals(zeroed);
Keep in mind, I’ve done quite a bit of googling to try to find an easy way to compare this. How do I compare the value of tempListPrice to see if it equals 0.00 , which is defined earlier as a big decimal datatype.
How do I do this? (Sorry Im quite new to Java).
Thanks
Okay, upon further research you will want equals or compareTo. You probably want
or
But honestly need to decide which better fits the semantics of your program. Keep in mind that the reason this is tricky is because floats don’t really have a notion of exactly equals, they’re intrinsically fuzzy, approximate entities. You will need to carefully review your code to make sure this is valid for your circumstances.
Anyway, the following points from the Javadoc should be enough for you to decide:
cf.