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

calculations in iReport


lknueve

Recommended Posts

 Can someone explain how calculations in iReport work? What the syntax is? Example: I have a field that I'm pulling - iReport is seeing it as an integer. I want to divide that field by a number for display purposes. I've tried the following based on what I've seen in other forum posts, but none are working...

new Double(($F{eventMsDuration}/(60*60)))
new Double(($F{eventMsDuration}/(60*60)).doubleValue())
new Double((double)($F{eventMsDuration}/(60*60))) -> gives reserved word error 

the top 2 examples give the following message: 

Error filling print... Error evaluating expression : 
    Source text : new Double(($F{eventMsDuration}/(60*60)))
Setting up the file resolver... 
net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : 
    Source text : new Double(($F{eventMsDuration}/(60*60))) 
    at net.sf.jasperreports.engine.fill.JREvaluator.evaluateEstimated(JREvaluator.java:259) 
    at net.sf.jasperreports.engine.fill.JRCalculator.evaluateEstimated(JRCalculator.java:580) 

 

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hi Giulio.

 

I'm still receiving the error? I'm currently using JavaScript as the report language so that I can use the SimpleDateFormat function....I tried your java example, also tried changing it to integerValue() since the field is originally an integer (in case that was the issue), but still received the same error. Does Groovy have any function that is similar to the SimpleDateFormat? If so, what is the syntax? Also, is there any place/book that has the syntax with the functions available?

 

Sorry for all the questions - I'm a newbie to both Jasper and Java....

Link to comment
Share on other sites

Groovy in Action is available on Amazon, and the second edition is due to come out some time this year I believe.  You can actually get a deal over at Manning.com where you can buy an electronic preview (they call it MEAP) of the second edition for $34.99, or if you pay $49.99, they also throw in a hardcopy of the book when it comes out.  I think that when you buy the electronic version of the second edition (before it's actually published), they also thrown in an electronic (PDF) copy of the entire first edition, so you're not missing out on anything while you wait for the second edition to be completed.

Okay, I'm not associated with Amazon (except giving them my hard-earned money continually!) or Manning, OR the book, so enough of the advertisement!

My understanding is that a Groovy Date object is a java.util.Date, so whether Groovy has any shortcuts for formatting dates or not, you could always fall back on any methods available in Java.

You might also check out the following sites: http://groovy.codehaus.org/JN0545-Dates

http://langref.org/groovy/dates

The latter reference shows the following two example Groovy statements right at the top of the page:

def date = new SimpleDateFormat("yyy-MM-dd HH:mm").parse("2008-05-06 13:29")

def date = Date.parse("yyy-MM-dd HH:mm", "2008-05-06 13:29")

Hope that helps!

Carl

Link to comment
Share on other sites

  • 2 years later...

Hi Giulio,

i have 3 columns a,b,c which are bigdecimal and i want to do a/b+c.

i tried many ways and deployed the report in jasper server it is getting me null.

please suggest what should i do about this.

whatever you mentioned above with groovy and java i tried which is getting me null.

 

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