Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Convert string to integer or float

Hi,
Do you Know an instruction to transform a string to an integer or a float in Tmap?
Thanks

Labels (2)
23 Replies
Anonymous
Not applicable
Author

Have a problem... try to convert string to int like this "5 600" from xls file. shows error
xception in component tMap_1
java.lang.NumberFormatException: For input string: "5 250"
at java.lang.NumberFormatException.forInputString(Unknown Source)
try to do like this
row1.Hotel_commissions.toString().equals("#") || row1.Hotel_commissions.toString().equals("") ? null :
Integer.parseInt(row1.Hotel_commissions.toString().replace(" ",""))
this not help
Anonymous
Not applicable
Author

ug. Java's not the best for string manipulation. in perl the correct solution would be:
my $input = "5 250"
my $output = do { $input =~ s/\s//g; };

I highly suggest checking out the Perl version of Talend. Perl was built for ETL and Talend makes writing powerful ETL scripts very fast.
Anonymous
Not applicable
Author

this is right if you want to drop.
Right conversion is made with Math.rint() or Math.round().or you can do it by hand:
float f = 234.33;
int i = (int)(f + 0.5f);
i has value 234
float f = 234.57;
int i = (int)(f + 0.5f);
i has value 235;
baskarchennai
Contributor
Contributor

Hi,
I want to parse a string and change the format as given below,
Input : C0003129872
Outpput : C=3129872
Could anyone tell me how can this be obtained pls?
Anonymous
Not applicable
Author

Hi baskarchennai,
You can do it by using this code:
StringHandling.CHANGE("C0003129872", "000", "=")

Regards,
Khor.
slim025
Contributor
Contributor

Hello,
I would like to know how I do in Talend to calculate the age of a person from his date of birth?
I know we need to use the current date, but I look for the syntax.
Thank you in advance
alevy
Specialist
Specialist

_AnonymousUser
Specialist III
Specialist III

More about......String to Integer
Biden
nar
Contributor
Contributor

i want to convert from float to double. i used this, "row1.doubleValue() " . now i'm facing null point exception error. Any suggestions.

manodwhb
Champion II
Champion II

@nareshm, you are getting null as part of data,so before converting to double handle nulls like this .

 

row1.Value==null ? row1.Value.doubleValue() : row1.Value