How to Convert string field to Decimal

Six Stars

How to Convert string field to Decimal

Hi Folks,

 

I want to do some sum operation on the  field called CHG_AMT. 

 

I am executing below logic,

row1.CHG_CLASS == "OCC" &&
(row1.CHG_DESC_1 == "Late Payment Charge" ||
row1.CHG_DESC_1 == "Late Charge on Past Due Balances" ||
row1.CHG_DESC_1 == "Late Fee" ||
row1.CHG_DESC_1 == "Finance Charge" ||
row1.CHG_DESC_1 == "Late Payment Interest" ||
row1.CHG_DESC_1 == "Late payment charge on unpaid balance") ?
sum(row1.CHG_AMT) : 0

 

The error I am facing is with data type of CHG_AMT in  the input.

 

So how do I convert this to Decimal and do Sum operation?

 

Any help is appreciated.

 

Thanks

Deepak

Eight Stars

Re: How to Convert string field to Decimal

Have you tried 

Double.parseDouble(row1.CHG_AMT)
Employee

Re: How to Convert string field to Decimal

What is the data type of AMT field coming as input & whats the data type of derived field? Based on that we can advice you conversion..

Six Stars

Re: How to Convert string field to Decimal

Input field is something like 23.34 which is of string type and need to convert that amount field suppose in the second line item will be 34.23. So I have to sum it up and show as amount field.

Moderator

Re: How to Convert string field to Decimal

Hello,

Have you already tried to use Double.parseDouble(name_of_your_input_field) or

new BigDecimal(name_of_your_input_field).doubleValue()

in tMap expression?

tAggregateRow component provides the aggregation key and the relevant result of set operations (min, max, sum...).

For a description of tAggregateRow, please check the documentation user guide.

TalendHelpCenter:tAggregateRow

Best regards

Sabrina

--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
Forteen Stars

Re: How to Convert string field to Decimal

use Double.parseDouble(sum(row1.CHG_AMT))

Manohar B
Don't forget to give kudos/accept the solution when a replay is helpful.
Moderator

Re: How to Convert string field to Decimal

Hello,

Is there any update for your issue?

Best regards

Sabrina

--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
Six Stars

Re: How to Convert string field to Decimal

No I have not got the solution yet. Suppose I have an input value like, 111.04 and I am using this in one subtraction from other field which is decimal(20,2) in Mysql and FLOAT(20,2) in Talend. 

 

I am getting data type issue, and it is not correctly calculated.

 

So how I can change the data type of field(which has 111.04) from String to Flo


@xdshiwrote:

Hello,

Is there any update for your issue?

Best regards

Sabrina



at conversion?

 

Regards,

Deepak

Forteen Stars

Re: How to Convert string field to Decimal

first you replace "," with "." using yourString.replaceAll(",", ".")) ,then you can covert using tConvert or Double.parseDouble() in tmap to convert.

Manohar B
Don't forget to give kudos/accept the solution when a replay is helpful.
Six Stars

Re: How to Convert string field to Decimal

I don't have , in the string value.

 

I just have something like below with decimal point.

 

24.56

32.45

 

Regards,

Deepak

Forteen Stars

Re: How to Convert string field to Decimal

ok,then you can use tConvertType or Double.parseDouble() in tmap to convert.

Manohar B
Don't forget to give kudos/accept the solution when a replay is helpful.
Forteen Stars

Re: How to Convert string field to Decimal

@Deepak1,did it help you?

Manohar B
Don't forget to give kudos/accept the solution when a replay is helpful.
Forteen Stars

Re: How to Convert string field to Decimal

@Deepak1,still do you have issue with this?

Manohar B
Don't forget to give kudos/accept the solution when a replay is helpful.

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

Definitive Guide to Data Integration

Practical steps to developing your data integration strategy.

Download