One Star

String to Double conversion in tmap

Hi,
I have 25 columns and have a requirement where in we need to search for a value in every column. Like if "Fuel Surcharge" is in ABCD then consider the amount value from the column ABCD_1, or if "Fuel Surcharge" is in EFGH then consider the amount value in EFGH_2, or if "Fuel Surcharge" is in IJKL then consider the amount value in IJKL_3, or if "Fuel Surcharge" is not in any of the following columns, then consider 0.
I have written the condition for the "Fuel Surcharge" column in tmap like,
row1.tracking_id_charge_description.equals("Fuel Surcharge")?Double.parseDouble(row1.tracking_id_charge_amount1)Smiley Sadrow1.tracking_id_charge_description1.equals("Fuel Surcharge")?Double.parseDouble(row1.tracking_id_charge_amount2)Smiley Sadrow1.tracking_id_charge_description2.equals("Fuel Surcharge")?Double.parseDouble(row1.tracking_id_charge_amount3):"0"))))))))))))))))))))))))
Here, Description columns has datatype String and Amount columns has datatype Double. I have written the above function for new column "Fuel Surcharge" which has a datatype Double.
When I Execute, I get this Error: Type mismatch: cannot convert from Object&Comparable<?>&Serializable to Double

Please Help

Regards,
Swathi
2 REPLIES
One Star

Re: String to Double conversion in tmap

Hi Swathi
I still remember we talked about this issue at 23342.
I think the most convenient way is not converting datatype in this expression.
Just choose String datatype in tMap. Then link it with tConvertType to change it from String to Double.
Your expression above is wrong. Because "0" is String. Double.parseDouble(row1.tracking_id_charge_amount3) is Double.
There are two datatypes in the same column.
Regards,
Pedro
One Star

Re: String to Double conversion in tmap

Hi Pedro,
Yes I have written that function with your help. I want the column to be double, because that column need to be used to create a metric. Thanks a lot again, will use tConvertType

Regards,
Swathi