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

Need to set a variable from a calculation


tkmbe

Recommended Posts

I have a report and need to calculate dependendent of an field some calculations and want to save this caululation in a variable to use in an other field.

For example I have a filed with the amount p_value which is an amount but in a string (from database) and want to divide it by 1.21 save this value and subtract from the amount and assign the result to an other variable.

How can I do that?

I tried to create an variable SUB_TOTAL

Variable Class: Double
Calculation: Nothing
Reset type: Report
Incremente type: None

which I try to add value

$V{SUB_TOTAL}.add(Double.parseDouble($F{p_value})/1.21)

or

$V{SUB_TOTAL}.set(Double.parseDouble($F{p_value})/1.21)

Nothing works...

The ultimate ireport designer guide should have at least an example of using variable this way in my opinion :-(

Thanks for any help

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Hi Teodor

I want to the the following:
Get total as double which is saved as string in database
  TOTAL=Double.parseDouble($F{p_value})
and calculate the following
  SUB_TOTAL=TOTAL/1.21
  IVA=TOTAl-SUB_TOTAL
if field iva_t=1
or in case iva_t !=0
  SUB_TOTALL=TOTAL
  IVA=0

How can I do that and how can I control the order of calculations
i.e. SUB_TOTAL is calculated before IVA?

Link to comment
Share on other sites

Hello

I have my calulation now:

($F{iva_t} == 1 ) ?  (new BigDecimal($F{p_value}).multiply(new BigDecimal($P{CambioDollar}))) : $F{p_value}

But I''m unable to save te result in a variable. How can I do that? Does I need scriplet for that?

Now I'm doing this calulation in a Textfield expresion. Is it unable to use and save in a variable in Textfields?

I need to save because I have a lot of calculations to do with this result ...

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...