Groovy expressions

I am trying to show a calculated field as a percentage. I have given the field type of BigDecimal and created an expression to display as one decimal percent.

My expression is:

($F{available}- $F{booked})/($F{available} - $F{sup_booked})

It works correctly when $F(available) and $F{booked} are
not same. When they are it gives 0 and it seems that the report requires 0.0 so I created the following expression:

($F{available}- $F{booked}) == 0? 0.0 : ($F{available}- $F{booked})/($F{available} - $F{sup_booked})

This one works fine but fails when both $F(available) and $F{booked} are zero.

Surely there must be a straightforward way of doing this calculation. Can somebody point out what I am doing wrong?

Regards
Rajeev
rajeevt's picture
47
Joined: Dec 30 2006 - 7:20am
Last seen: 16 years 9 months ago

0 Answers:

No answers yet
Feedback
randomness