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

Error Tmap String to float

Hello,

 

I'm new at talend and i'm trying to convert string to float and i facing many issues.

The tConvertType is not working for me, give me this error 

For input string: "1,37"
For input string: "1,37"
For input string: "1,37"
For input string: "1,37"
For input string: "1,37"
For input string: "1,37"
For input string: "0,72"
For input string: "0,72"
For input string: "0,72"
For input string: "0,72"
For input string: "0,72"
For input string: "0,72"

For input string: "1.000,72"

 

Yes, my input data source is a string with "." and ",".

 

Now, i'm trying with the tMap

 

using the expression below :  Float.parseFloat(StringHandling.EREPLACE(row1.KUS,",","."))

but stil not working

 

error 

 


Exception in component tMap_2 (Transform_MetaDados)
java.lang.NumberFormatException: multiple points
 at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1914)
 at sun.misc.FloatingDecimal.parseFloat(FloatingDecimal.java:122)
 at java.lang.Float.parseFloat(Float.java:451)
 at extract_to_oracledb.transform_metadados_0_1.Transform_MetaDados.tDBInput_2Process(Transform_MetaDados.java:1474)
 at extract_to_oracledb.transform_metadados_0_1.Transform_MetaDados.runJobInTOS(Transform_MetaDados.java:2144)
 at extract_to_oracledb.transform_metadados_0_1.Transform_MetaDados.main(Transform_MetaDados.java:1994)

Labels (3)
1 Solution

Accepted Solutions
guratalgura
Contributor II
Contributor II

Hi, 

try this:

Float.parseFloat(StringHandling.EREPLACE(StringHandling.EREPLACE(row1.KUS,"\\.",""),",","\\."))

 

Regards

View solution in original post

6 Replies
David_Beaty
Specialist
Specialist

Hi,

 

I'd suggest you do this as a series of steps in the tMap Var section:

 

1/ String in -> remove the dots (1.000,72) -> (1000,72)

2/ Step 1 String in -> convert the commas to dots (1000,72) -> (1000.72)

3/ Step 2 String in -> parse string to float.

 

Thanks

 

Anonymous
Not applicable
Author

How is the better way to remove the dots

I'm trying this

StringHandling.EREPLACE(row1.KUS,"."," ")

Exception in component tMap_4 (Transform_MetaDados)
java.lang.NumberFormatException: empty String
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1842)
at sun.misc.FloatingDecimal.parseFloat(FloatingDecimal.java:122)
Anonymous
Not applicable
Author

hello,

you can try this:- 

 

Float.parseFloat(row1.myString)

 

thanks,

 

 

 

Warm Regards,
Manish

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

guratalgura
Contributor II
Contributor II

Hi, 

try this:

Float.parseFloat(StringHandling.EREPLACE(StringHandling.EREPLACE(row1.KUS,"\\.",""),",","\\."))

 

Regards

Anonymous
Not applicable
Author

Perferct! Thanks, this working for me..

But in other columns i'm facing another issue, probaly because i have null values.

i tried this expression

row2.QTDE_REC_2.equals("null")0:Float.parseFloat(StringHandling.EREPLACE(StringHandling.EREPLACE(row2.QTDE_REC_2 ,"\\.",""),",","\\."))

AND RECEIVE THIS ERROR :

Exception in component tMap_2 (Transform_MetaDados)
java.lang.NullPointerException
at extract_to_oracledb.transform_metadados_0_1.Transform_MetaDados.tDBInput_2Process(Transform_MetaDados.java:2207)
at extract_to_oracledb.transform_metadados_0_1.Transform_MetaDados.runJobInTOS(Transform_MetaDados.java:3032)
at extract_to_oracledb.transform_metadados_0_1.Transform_MetaDados.main(Transform_MetaDados.java:2882)

Could you suggest something diferent ?

I'm aprecciente your help


guratalgura
Contributor II
Contributor II

Hi,

You can use the ternary oparator to check the null or empty row before formatting

 

try this :

(row2.QTDE_REC_2 != null && !row2.QTDE_REC_2.isEmpty()) ? Float.parseFloat(StringHandling.EREPLACE(StringHandling.EREPLACE(row2.QTDE_REC_2,"\\.",""),",","\\.")): 0

 

Regards,