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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

String to Float conversion

Hi Talend community,
I have a problem with converting from String to Float.
This is my input:
3 11 29 0 01020 50 8101 0100 0000 0 000
0 00 00 0 00000 00 0000 0000 0000 0 000
0 00 00 0 00000 00 0000 0000 0000 0 000
Expected output:
3 11 29 0 01020 50 81.01 01.00 00.00 0 000
0 00 00 0 00000 00 00.00 00.00 00.00 0 000
0 00 00 0 00000 00 00.00 00.00 00.00 0 000

I've tried with Float parse and put precision of 2 at tMap. But the output only display 0. Does this has something to do with 0 value.
Thanks in advance!
Labels (2)
12 Replies
Anonymous
Not applicable
Author

Hi Rozie,
All right here are steps to create all things step by step.
1. Create a routine named with "NumericConversion"
2. paste below function in it.
public static BigDecimal GetDecimalFromFixedString(String Column,int Precision)
{
BigDecimal Result= new BigDecimal("0.00");
String s = Column.substring(0,((Column).length()- Precision));

String ss =Column.replace(s, "");
Result =new BigDecimal(s+"."+ss);
return Result =new BigDecimal(s+"."+ss);
}

3. import required name spaces.
4. open tMap and use function like below.
yourcolumn!=null?
NumericConversion.GetDecimalFromFixedString(yourcolumn,decimalpointposition):new BigDecimal("0")

I am busy in some work so writing in very short words.
Anonymous
Not applicable
Author

Hi umeshrakhe,
I'm sorry if my prob keeps bugging you. I'm however still receiving error.
My code follows exactly as you are:
package routines;
public class NumericConversion {
public static BigDecimal GetDecimalFromFixedString(String Column,int Precision)
{
BigDecimal Result= new BigDecimal("0.00");
String s = Column.substring(0,((Column).length()- Precision));

String ss =Column.replace(s, "");
Result =new BigDecimal(s+"."+ss);
return Result =new BigDecimal(s+"."+ss);
}
}

Attached are the image files of the errors I received.
Regards,
Rozie
0683p000009MDwi.jpg 0683p000009MDro.jpg 0683p000009MDwn.jpg
Anonymous
Not applicable
Author

Hi Rozie
It is a compilation error here, use java.util.BigDecimal instead of BigDecimal in your routine
for example:
 BigDecimal Result= new BigDecimal("0.00");

to
 java.math.BigDecimal Result= new java.math.BigDecimal("0.00");

Shong