BigDecimal
Posted by Mike Haller
on Friday, March 16. 2007
at 23:31
I've done a lot of String Concatenations to convert ints to Strings, so I can create BigDecimals. After some time, i learnt that this is ugly. Code like this can be found everywhere (not only in my code)private static String EMPTY_STRING = ""; int invoiceNumber = 123; new BigDecimal(EMPTY_STRING + invoiceNumber);
Why don't we use the much simpler form?
BigDecimal.valueOf(invoiceNumber);
Isn't this much easier to read andunderstand? Why the heck do we do such horrible things in the first place? A customer asked me and my collegue why we often use the term ""+int to convert something into a String and I couldn't give him an answer. I was so shocked as it turned out to be true and that I didn't know why I did that stuff over and over again.
Bad habits last long.
