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

How to convert String to INT/Double in groovy?


nephalem

Recommended Posts

Hello,

I am pretty new to Jasper Reports and I try to do some reporting from a MySQL Database in iReport.

I managed to split the String the way i needed it (get rid of all the unimportant text etc.) so it contains nothing but numbers.

The Problem is: How do i convert the (String) numbers to a "real" number i can do calculations with in groovy?

For Numbers there are various methods but i didnt see any easy way to convert a String to an Int or Double.

 

Hope you can help me.

 

Many thanks in advice

Nephalem

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Question is my sugesstion right that I can implement more functions to iReports Expression?

I found the function praseInt() but this function and others like, .getInteger(String) or valueOf(String) is just returning an null.... do you know why? 

Thats my expression in the properties of a Variable called intTest... and the field Gesamt Brutto is a String containing numbers as string...:

$V{intTest}.parseInt($F{Gesamt Brutto})

$V{intTest}.valueOf($F{Gesamt Brutto})

$V{intTest}.getInteger($F{Gesamt Brutto})

 

everything is not working... I'm using Groovy =/



Post Edited by adiboing at 06/27/2011 07:00
Link to comment
Share on other sites

My guess is that the problem is that you are calling static functions of the class Integer and expecting it fill in the value of your Integer variable.  Assuming this is the "Variable Expression" property of your $V{intTest} variable, you don't need to put the name of your variable in the expression.  Just put an expression that will evaluate to the value you want iReport to put in your variable.  In the case of a static method from the class Integer, just replace your $V{intTest} with the name of the class:

$V{intTest} property panel:

 

Variable Expression:     Integer.parseInt($F{Gesamt Brutto})

 

Carl

Link to comment
Share on other sites

  • 1 year later...

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