Tuesday, July 5, 2011

BigDecimal to String conversion

We have just realised one more non obvious issue with toString() method of BigDecimal while migrating from jdk1.4 to 1.6

Since Java 5, the toString method started printing the value in scientific form if scale is more than 6, so our messages going out have become wrong; no coding issues, its like silent killer :-)  Good lesson for me is to override this method whenever the output make a difference even though the default is enough.  The new method added is toPlainString() to get what toString() is doing earlier.