Convert String to Number

0

Hello,
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?
 
Markus
 
 

 

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

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

Markus

makroll10 - 3 years 11 months ago

Hi  

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.

Example

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:

-8

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

http://stackoverflow.com/

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

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

Regards,

Lucian

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