The Artima Developer Community
Sponsored Link

Java Buzz Forum
Getting around BigDecimal pain with Groovy

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
dion

Posts: 5028
Nickname: dion
Registered: Feb, 2003

Dion Almaer is the Editor-in-Chief for TheServerSide.com, and is an enterprise Java evangelist
Getting around BigDecimal pain with Groovy Posted: Aug 1, 2005 6:46 PM
Reply to this message Reply

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
Latest Java Buzz Posts
Latest Java Buzz Posts by dion
Latest Posts From techno.blog(Dion)

Advertisement

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.

Read: Getting around BigDecimal pain with Groovy

Topic: TDD + Debuggers = Test Driven Bug Fixing Previous Topic   Next Topic Topic: Trouble With SELinux On "Production" Server

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use