Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello everyone;
Im currently trying to transform some data but I need to use LPAD (I think) and cant find a good way :
My value :
459,55
45
41
105,32
104,78
I need it transform to 13 characters with 3 digits, and NO , or .
so it should look like
0000000459550
0000000045000
0000000041000
0000000105320
0000000104780
I want to multiply by 1000 and then LEFTPAD 0 until thirteen, is it the best way to do so ?
Im having trouble findind the good type, if i use Float; since there is a , it doesnt multiply.
What i tried :
row1*1000 but it return value with .0 ( 41 > 41000.0 for example)
.multiply cant work (
method multiply(int) is undefined for integer)Can someone explain to me which type should i use and how can i manage to LPAD and multiply a decimal value ?
Thanks
Finally found a way :
String.format("%013d", Math.round(row1.quantity*1000))
@Bourgin Benoit , check the below case will help you.
https://community.talend.com/s/feed/0D73p000004kQzOCAU
Thanks,
Manohar
Hello @Manohar B ,
Thanks for your help. I see this post but its not helping.
I can manage to LPAD my string. But i need 3 digits all the time, and for 105,32 it returns 0000000010532 instead of 0000000105320. I tried this :
String.format("%013d", Integer.parseInt(row1.qty))
But since my data is with comma, I think it doesnt work.
java.lang.NumberFormatException: For input string: "0,035"
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:68)
at java.base/java.lang.Integer.parseInt(Integer.java:652)
at java.base/java.lang.Integer.parseInt(Integer.java:770)
Reminder : data set is like 0,035 or 142,35 , string value.
I need my output 13 char long AND 3 digits, no separtor. So LPAD is not enough.
Should be 0000000000035 and 0000000142350 for those previous value.
Any help appreciated !
Still actively looking for a way to deal with it
Finally found a way :
String.format("%013d", Math.round(row1.quantity*1000))