Worlds Colliding Violently

Worlds Colliding Violently

Programming, Drumming, Cooking, Cars, Mozilla, and the Trials & Tribulations of a Geek from New Jersey.

Worlds Colliding Violently RSS Feed
 
 
 
 

BigDecimal – BigAnnoyance

Nils got it right nearly three years ago, but it’s still very much broken here in 2009.

A calculation as simple as (289898-54545) / 54545 will throw a fun java.lang.ArithmeticException error.

It’s a good test calculation, because the resulting number, 4.314840957007975066458887157393[...], is a good precision test, and sure enough, it will cause an error every time. Get around it with a scale (in this case 10), and a BigDecimal.ROUND_HALF_UP RoundingMode.

Leave a Reply

You must be logged in to post a comment.