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

0

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

matthew.friend@ars.usda.gov's picture
Joined: Jul 16 2017 - 1:57pm
Last seen: 2 months 1 week ago

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

That worked for me :)

Matthew

matthew.friend@ars.usda.gov - 2 months 1 week ago

2 Answers:

0

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

C-Box's picture
2296
Joined: Jul 19 2006 - 5:58pm
Last seen: 1 month 2 weeks ago
0

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.

Pawan

pawankumar.singh's picture
Joined: Sep 19 2018 - 10:39pm
Last seen: 1 month 2 weeks ago
Feedback
randomness