Facelets: JSF down right…. but what do you give up? The need for a common Java stack
Aug 01

Getting around BigDecimal pain with Groovy

Groovy, Java, Tech Add comments

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.


def x = 10;

println x.class;

(1.0..100.0).step(20) { y ->
println x;

x = x * y;

println x.class;


class java.lang.Integer
class java.math.BigDecimal

Note the auto change, and how operators such as * / – + all JUST WORK.

9 Responses to “Getting around BigDecimal pain with Groovy”

  1. Toni Says:

    Yeah, looks nice. But then again – what happens if you’d try to use Math.sin() or a Math.sqrt(). These aren’t defined for BigInteger. Wouldn’t your script crash with a ClassCastException (or something like that) if your int suddently changes int a BigInteger? After all *this* is the most painful stuff that you have to deal with, when using BigInteger, not simple artithmetics.

  2. Scott Says:

    Simple math gets pretty painful with BigDecimal.
    Simple math gets pretty painful with BigDecimal.
    Simple interpolation in Groovy looks like it did in high school:
    (lowerValue*(upperBound-value) + upperValue*(value-lowerBound)) / (upperBound-lowerBound)

    In Java (I think?):
    lowerValue.multiply(upperBound.subtract(value)).add(upperValue.multiply(value.subtract(lowerBound))).divide(upperBound.subtract(lowerBound), 10, BigDecimal.ROUND_HALF_UP);

  3. ativan Says:

    I think this topic is very different and should be more pages like this,Your
    comment says a lot of truth, it’s very actually, and I’d like to invited you
    to visit my page:10/325-
    Vicoprofen – Lortab- Tylenol
    #3- Ativan
    All Major Medications are available right here at: http://www.crdrx.com

  4. Michalis Says:

    See you…Thanks, its great to receive such positive comments.
    tylenol for dog infant tylenol dosage
    [url=http://tylenol.exegma.info/overdosing-on-tylenol--.html] overdosing on tylenol [/url][url=http://tylenol.exegma.info/tampering-tylenol---.html] tampering tylenol [/url][url=http://tylenol.exegma.info/motrin--.html] motrin [/url][url=http://tylenol.exegma.info/tylenol-pm.html] tylenol pm [/url]

  5. Andreas Says:

    hello, your site is lucky.
    infant tylenol cold tylenol packaging case study cold flu tylenol
    [url=http://tylenol.exegma.info/baby-tylenol.html] baby tylenol [/url][url=http://tylenol.exegma.info/generic-tylenol.html] generic tylenol [/url][url=http://tylenol.exegma.info/tylenol-pm-overdose.html] tylenol pm overdose [/url]

  6. Agapios Says:

    Hello, nice site look this:
    lolicon lolikon 3d lolikon toons grand lolikon
    [url=http://lolikon.lll1l.info/lolikon-anime--.html] lolikon anime [/url][url=http://lolikon.lll1l.info/lolikon-video---.html] lolikon video [/url][url=http://lolikon.lll1l.info/3d-lolikon-toons---.html] 3d lolikon toons [/url]

  7. Loukas Says:

    Nice! We really amused by the website.
    lolikon tgp 3d lolikon
    [url=http://lolikon.lll1l.info/lolikon-picture.html] lolikon picture [/url][url=http://lolikon.lll1l.info/lolikon-hentai--.html] lolikon hentai [/url]

  8. hi Says:


  9. julio roberto Says:


Leave a Reply

Spam is a pain, I am sorry to have to do this to you, but can you answer the question below?

Q: Type in the word 'ajax'