Convert String to Number


in iReport i want to read with the "substring" function a part from a text field like: $F{Textfeld}.substring(5, 9)

For example of

"10000 015" the part "015"
"20000 023" the part "023"
"30000 057" the part "057"

After that I want to create a variable $V{Sum} (typ = java.lang.Integer, calculation  = sum), to convert the results in a number and create a sum. In the example it is 95.

Unfortunately, it has been abort with "java.lang.String cannot be cast to java.lang.Number".
But what is wrong with it?


makroll10's picture
Joined: May 20 2014 - 4:20am
Last seen: 8 months 2 weeks ago

a reference to another board is/ was not the solution to the problem.

I Think the problem lies in the conversion of the string through by the substring command
and the subsequent conversion into the variable...


makroll10 - 3 years 11 months ago


Parsing Methods in Java Convert String to Int

In Java there are two methods to convert String to Int, they are.

  1. Integer.parseInt()
  2. Integer.valueOf()

1. Convert String to Int using Integer.parseInt()

The Integer.parseInt() is a static method of Integer class used in java to converts string to primitive integer.


String ‘100’ to primitive integer 100

Note:Parsing is a process of converting one data type to another. For example String to integer is a best way to convert string to int  i hope this may be use full.

kavyatg1990 - 1 year 9 months ago

2 Answers:


Should go to StackOverflow and ask there how to convert String to Integer in Java.

hozawa's picture
Joined: Apr 24 2010 - 4:31pm
Last seen: 7 months 3 weeks ago

You need to manually convert the String into an integer by doing Integer.valueOf($F{Textfeld}.substring(5, 9)) or INTEGER_VALUE($F{Textfeld}.substring(5, 9))

(INTEGER_VALUE is a builtin function available in recent versions, it might not work in iReport.)



lucianc's picture
Joined: Jul 17 2006 - 1:10am
Last seen: 1 week 4 days ago