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

Convert string to double


nealhudson

Recommended Posts

Hi

I'd like to convert a string to a double. The issue is that sometimes the string does not contain numeric data.

 

I was thinking of placing a try catch block in the value expression for a variable.

Something like this:

 

try{

new java.lang.Double(java.lang.Double.parseDouble($F{Time}));

}

catch(NumberFormatException e){

new java.lang.Double(0);

}

 

where $F{Time} is a string field returned from the database.

 

However, I keep getting the following errors when trying to compile the report:

Syntax error on token "(", ; expected

Syntax error on token ")", delete this token

Link to comment
Share on other sites

  • Replies 9
  • Created
  • Last Reply

Top Posters In This Topic

Hi!

If you are using SQL ... any way of converting the string field into a double field in the SQL query already?

 

Otherwise, the only way I see is writing a scriptlet that contains a "non-throwing" conversion function, and deploy the scriptlet together with the report, as svenn already mentioned ...

 

Sebastian

Link to comment
Share on other sites

  • 2 years later...
  • 1 year later...

Works with...

Set " Text Field Expression " : Double.parseDouble($F{PARAM})
Set " Expression Class " : java.lang.Double

Add rt.jar (from java runtime) to classpath [ Tools >> Options >> Classpath]

And Compile

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