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

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's picture
Joined: Jul 16 2017 - 1:57pm
Last seen: 3 months 4 weeks ago

Thank you C-Box and Pawan for both of your helps, I appreciate it.

That worked for me :)

Matthew - 2 years 7 months ago

2 Answers:

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);

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);

hth + regards


C-Box's picture
Joined: Jul 19 2006 - 5:58pm
Last seen: 2 months 3 weeks ago

when you are creating variable then you can do 
First you just create variable and provide value class name like if you want to divide it by 3 then your field must be class of double/integer/long. After that you are able to divide by 3.
eg. $V{CORN1_MEASURE}.doubleValue()/3 try this.

Hope this will help.


pawankumar.singh's picture
Joined: Sep 19 2018 - 10:39pm
Last seen: 2 years 6 months ago