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

Convert String to Number


makroll10
Go to solution Solved by hozawa,

Recommended Posts

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
 
 

 

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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

Link to comment
Share on other sites

  • 2 years later...

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.

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