Jump to content

Calculate % of 2 Variables(java.math.BigDecimal)?


rghanta

Recommended Posts

I have two Variables whose Variable Class Types are "java.math.BigDecimal". My requirement is to calculate the percentage of those two Variables and display it in the format "XY %". Something like ((Variable1/Variable2)*100) in plain mathematics. I see some methods like divide(), multiply() etc in the Expression Editor. But I am not sure of how to use those expressions. Can some body help me to achieve this in iReport.

Thanks in advance.

Best Regards,

Ram...

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

There are a couple of ways of doing this.

1. Create a new text field

2. Right click on the text field and go to Properties then Text Field tab

3. Change the Text Field Expression Class to java.lang.Double

4. Now enter the following in the Text Field Expression box

new Double($V{yourvariable2}.doubleValue() == 0 ? 0 :
($V{yourvariable1}.doubleValue()/$V{yourvariable2}.doubleValue()))

In order to change the pattern, simply go to pattern > create > percentage and select your desired pattern.

Hope this helps!

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