Search code examples
hibernateplsqlbigdecimal

BigDecimal 0.000 to 0


I am testing with JUnit a PLSQL procedure , to his "equals" in Java/Hibernate. One result in PLSQL it is 0 but the Java result it is 0.0000, I tried using function called stripTrailingZeros but didn't work. I think for practical terms there are the same but not sure at all.

EDIT I want to remove the zeros who does not have numerical significance for example

2.3400 > 2.34

I can do it with stripTrailingZeros but when i Apply that function over return the same thing:

0.0000 > 0.0000


Solution

  • You are doing the right thing, but the implementation of the method is wrong. In other words, Java is broken. There is a bug report about this issue but it doesn't seem to be resolved yet. A Customer Submitted Workaround is included in the link. Basically, do an explicit compareTo with new BigDecimal("0"), which works correctly.