This post originated from an RSS feed registered with Java Buzz
by dion.
Original Post: Getting around BigDecimal pain with Groovy
Feed Title: techno.blog(Dion)
Feed URL: http://feeds.feedburner.com/dion
Feed Description: blogging about life the universe and everything tech
BigDecimal is a necessary evil, isn't it. Without it, you end up over-running primitive bounds and suddenly your results are weird "what is with the negative numbers?".
I was talking with someone whose "users" are uber-intense actuaries.
They need to be able to write quick reports, and change functionality on the fly.
Rather than using full on Java, they interfaced via a scripting language, to give them concise scripts versus the verbosity that we know and love from Java :)
JavaScript was one choice, but they quickly ran into problems with double/float/int/BigDecimal, and they had to manually do a lot of work with BigDeminal objects and methods.
Then along came Groovy, which automatically groks the fact that it should take care of autogrowing the world.
E.g.
def x = 10;
println x.class;
(1.0..100.0).step(20) { y ->
println x;
x = x * y;
}
println x.class;
Output
class java.lang.Integer
10
10.0
210.00
8610.000
525210.0000
class java.math.BigDecimal
Note the auto change, and how operators such as * / - + all JUST WORK.