Jump to content
We've recently updated our Privacy Statement, available here ×

Videos or practical examples on doing math with variables in Jaspersoft Studio


Go to solution Solved by C-Box,

Recommended Posts

Hi Folks:

I tried reading the latest Studio user guide chapter on Variables but I'm looking for some practical examples.  Videos or practical examples on how to work with them would be great.

For example:   I have a totals field that is the sum of x3 fields.  I want  to be able to take the variable:   $V{CORN1_MEASURE}        and divide it by three.   I've tried reading the chapter on variables but still can't get it.     What I want is something like: $V{CORN1_MEASURE} / 3

http://cwebpro.com/crosstab_jaspersoft.png

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

  • Solution

if you use some BigDecimal types for your measures you must be aware of the RoundingMode and the expected scale. ... eg following divides by 3 and rounds half up and set the scale to 2 digits after the decimal separator:

$V{CORN1_MEASURE}.divide(new BigDecimal(3), 2,  BigDecimal.ROUND_HALF_UP);[/code]

Be aware that your measure isn't null.... otherwise make a simple If-Then-Else Check before:

$V{CORN1_MEASURE} == null ? BigDecimal.ZERO : $V{CORN1_MEASURE}.divide(new BigDecimal(3), 2,  BigDecimal.ROUND_HALF_UP);[/code]

hth + regards

C-Box

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...