Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Conversion from string to float

Hi,
I am getting data in text format (positional format) and want to check if the string is null then assign 0.0 else divide the incoming string by 100
trying following expression but getting error "Exception in thread "main" java.lang.Error: Unresolved compilation problems:"
row2.fta_fare_amt.equals(null) ? Float.parseFloat("0.0")
: Float.parseFloat(row2.fta_fare_amt)
Unable to figure out what's the issue, need some help.
Thanks,
Milind
Labels (3)
6 Replies
Anonymous
Not applicable
Author

Hello Milind
row2.fta_fare_amt.equals(null) ? Float.parseFloat("0.0")
: Float.parseFloat(row2.fta_fare_amt)

Change it to
row2.fta_fare_amt==null?  Float.parseFloat("0.0")
: Float.parseFloat(row2.fta_fare_amt)

Best regards

shong
Anonymous
Not applicable
Author

Hi Shong,
Here is the error I am getting after putting the code that you mentioned above
--
Exception in component tMap_9
java.lang.NumberFormatException: empty String
at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
at java.lang.Float.parseFloat(Unknown Source)
--
where input string is string and output string is float , Do I need to change the datatype ?
Thanks,
Milind
Anonymous
Not applicable
Author

Hello
This code should work fine
row2.fta_fare_amt==null||row2.fta_fare_amt.equals("")?  Float.parseFloat("0.0")
: Float.parseFloat(row2.fta_fare_amt)

Best regards

shong
Anonymous
Not applicable
Author

Thanks Shong ... still the same error .. there is one more Int column, if following syntax correct, getting complilation error
row2.fta_chk_dgt_tkt_doc_nbr==null||row2.fta_chk_dgt_tkt_doc_nbr("")? Integer.parseInt("0")
: Integer.parseInt(row2.fta_chk_dgt_tkt_doc_nbr)
Thanks,
Milind
Anonymous
Not applicable
Author

looks like the error is still for the float
Exception in component tMap_9
java.lang.NumberFormatException: empty String
at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
at java.lang.Float.parseFloat(Unknown Source)
Thanks,
Milind
Anonymous
Not applicable
Author

Hello guy
row2.fta_chk_dgt_tkt_doc_nbr==null||row2.fta_chk_dgt_tkt_doc_nbr("")? Integer.parseInt("0")

fta_chk_dgt_tkt_doc_nbr("")? ?????!!! please check your code, there is an error in your code.
Best regards
shong