How to convert String to INT/Double in groovy?

0

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

nephalem's picture
Joined: Jun 24 2011 - 12:03am
Last seen: 3 years 3 months ago

5 Answers:

0

I just tried Integer.parseInt($F{StringField}), and it worked fine for me.  Hope that helps.

 

Carl

cbarlow3's picture
802
Joined: Mar 4 2010 - 8:59am
Last seen: 1 month 4 days ago
0

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
adiboing's picture
Joined: Nov 24 2010 - 5:07am
Last seen: 3 years 10 months ago
0

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

cbarlow3's picture
802
Joined: Mar 4 2010 - 8:59am
Last seen: 1 month 4 days ago
0

i solved my problem by using $V{Variable}.toInteger() which returns the string as Integer. unfortunately the build-in editor didnt show me this possibility but google did

nephalem's picture
Joined: Jun 24 2011 - 12:03am
Last seen: 3 years 3 months ago
0

deleted



Post Edited by shteng87 at 07/06/2012 03:09
shteng87's picture
Joined: Aug 10 2011 - 1:37am
Last seen: 3 years 1 month ago
Feedback