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

Want to do math on variables


evalentine

Recommended Posts

I want to take the sums of two columns and add together. The first column is the hours, the second is the minutes. Something like;

$V{tot_hours} = (($F{hours}  *  60)  + $F{minutes} )   / 60)

This will equal the total number of hours as a decimal. Then I can multiple by the hourly rate.

 

Any suggestions?

Thanks.

Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

why don't you use a variable for each column you want to sum?

you can define:
a variable $V{sum_hours} that is the sum of all hours that you have in your report...
a variable $V{sum_minutes} that is the sum of all minutes that you have in your report...

and then use this variables:

$V{tot_hours} = (($V{sum_hours}  *  60)  + $V{sum_minutes} )   / 60)
 

 

 

 

 

 

________________________________
if it works... KARMA point please!    : )  

Link to comment
Share on other sites

use the intValue() when you want the int from an Integer... so:

define $V{tot_hours} as Integer

and set the expression as:

  new Integer((($V{sum_hours}.intValue()  *  60)  + $V{sum_minutes}.intValue() )   / 60)

if you want use with integer values...
if you prefer double or float value use Float or Double types...

read this for basic usage of the primitive wrapper java class:

http://en.wikipedia.org/wiki/Primitive_wrapper_class

 

 

______________________________
if it works... KARMA point please!    : ) 



Post Edited by slow at 04/07/2010 07:16
Link to comment
Share on other sites

I am still not getting this correct.

The variables are defined as java.lang.Integer.

If I use:

((($V{timeproj_h_2}.intValue()  *  (60))  + $V{timeproj_m_2}.intValue() )   / (60))

I get cannot cast int to integer.

If I use:

((($V{timeproj_h_2}  *  (60))  + $V{timeproj_m_2})   / (60))

I get :

* is undefined for the argument type Integer,int.

 

I seem to be lost in Value Type Hell.

Any suggestions to explain this or just get around it?

Thanks.

 

 

 

 

Link to comment
Share on other sites

if you read better my last post :

new Integer((($V{sum_hours}.intValue()  *  60)  + $V{sum_minutes}.intValue() )   / 60)

you MUST create a new Integer value... it's only JAVA rule! :)

 

______________________________
if it works... KARMA point please!    : )

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