How to convert a string value of format “$$$$$$$$$$$cc" "0000000001600"?

Highlighted
Seven Stars

How to convert a string value of format “$$$$$$$$$$$cc" "0000000001600"?

Hello Talend Community

 

I am new to Talend and JAVA all together.

 

How would I convert a string value of format “$$$$$$$$$$$cc" "0000000001600" for example would convert to string 16.00 with expression builder in a tMap component.

 

I know I can get rid of the starting zeros with StringHandling.RIGHT(“000000000” + row1.amt)

 

I just need to figure out how to add the period so it's 16.00 and if I had an amount of 160.00 in my amt column how would I ensure the 1 wouldn't get trimmed and for 1600.00 I checked that my field and no amount goes over 9999.00. 

 

Any help would be greatly appreciated!!

 

If there is a Java Script Function tool or documentation out there that help me understand the JavaScript expression builder syntax better that would be an added bonus!

 

 

 

 


Accepted Solutions
Employee

Re: How to convert a string value of format “$$$$$$$$$$$cc" "0000000001600"

Hi,

 

     You can achieve the functionality by below flow. In the example, I am generating the data but in your case, you will be using input data flow.

image.pngdata flow

 

image.pngoutput for $16image.pngOutput for $1600

 image.pngtmap output

 

Value for interim_amt_value in Var


row2.amt.replaceFirst("^0+(?!$)", "") 
Value for output_amount

Var.interim_amt_value.substring(0,Var.interim_amt_value.length()-2)+"."+Var.interim_amt_value.substring(Var.interim_amt_value.length()-2) 

Warm Regards,
Nikhil Thampi

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 :-)


All Replies
Employee

Re: How to convert a string value of format “$$$$$$$$$$$cc" "0000000001600"

Hi,

 

     You can achieve the functionality by below flow. In the example, I am generating the data but in your case, you will be using input data flow.

image.pngdata flow

 

image.pngoutput for $16image.pngOutput for $1600

 image.pngtmap output

 

Value for interim_amt_value in Var


row2.amt.replaceFirst("^0+(?!$)", "") 
Value for output_amount

Var.interim_amt_value.substring(0,Var.interim_amt_value.length()-2)+"."+Var.interim_amt_value.substring(Var.interim_amt_value.length()-2) 

Warm Regards,
Nikhil Thampi

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 :-)

Seven Stars

Re: How to convert a string value of format “$$$$$$$$$$$cc" "0000000001600"

Hey Nikhil,

 

Thanks for your knowledge and expertise for this answer that you provided.

 

This worked as expected for my input file.

 

Is there any good documentation that Talend provides on the syntax on manipulating string values. I just want to get familar with the java script language so I can figure these conversions out by myself in the future. Even if the resource book/tutorials cost any money I am willing to pay the fee to learn.

 

Thanks again,

 

Andrew

Employee

Re: How to convert a string value of format “$$$$$$$$$$$cc" "0000000001600" for example would convert to string 16.00 with expression builder in tMap

Hi Andrew,

 

      I am happy to know that it helped to resolve your use case :-)

 

      At present we are not giving any Java specific training for Talend. The best place where I go for reference is stackoverflow for java related queries. You can good code snippets which you can easily add to tMap and other Talend components.

 

     End of day, Talend is a java code generator. So any properly created java function will work seamlessly in Talend. But if you are stuck somewhere, our  Talend community members are always there to help you :-)

 

Warm Regards,
Nikhil Thampi

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 :-)

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Downloads and Trials

Test drive Talend's enterprise products.

Downloads