cancel
Showing results for 
Search instead for 
Did you mean: 

String to Decimal Format in Mapping UDF

nidhi_srivastava22
Active Contributor
0 Kudos

Hi Experts,

I have a requirement where I am getting values in string which I am using as multiply later which is failing due to mismatch in type.The input structure of the queue is mentioned below-

112

110

[]

[]

[]

100

Using the UDFs mentioned in various scn links

Double f=Double.parseDouble(var1[0]);

result.addValue(f);

Output structure-

112

I want the the output structure for all the queue values, tried many options but its not working. Can anyone please suggest some easy options?

Thanks,

Nidhi Srivastava

Accepted Solutions (1)

Accepted Solutions (1)

nidhi_srivastava22
Active Contributor
0 Kudos

Hi Manoj,

It was showing the same exception(NumberFormatException) as shown in the screenshot attached.

This is fixed without java code. As per your suggestion, I have handled null values using if else condition and mapping to "0" if there are null values. Post that, FormatNum is used and it is working perfectly fine.

Thanks.

Best Regards,

Nidhi Srivastava

Answers (3)

Answers (3)

nidhi_srivastava22
Active Contributor
0 Kudos

Thanks for your inputs Manoj, but it is still not working with this code.

I will try to handle null value replacement by some valid value and then try.

Thanks,

Nidhi Srivastava

manoj_khavatkopp
Active Contributor

Can you please explain why that is not working ? Because i have tried that in my system and it does not throw any error.

former_member190293
Active Contributor
0 Kudos

Hi Nidhi!

Please follow Manoj's suggestion.

By the way, your input queue contains multiple contexts, so, you should include the logic to process "__Cc_" (context change) values in your UDF. Another way is to change processing mode for the UDF to single value or all values of the context. Also you can change context of your input queue to move all the values to single context (by changing context or using RemoveContexts function).

Regards, Evgeniy.

former_member190293
Active Contributor
0 Kudos

Hi Nidhi!

I guess you should spend some time on learning java basics.

You parse only the first value (index - 0) and add the result to output queue. In order to get all values you shoud use loop at your whole unput queue:

for (int i = 0; i < var1.length; i++)...

Regards, Evgeniy.

nidhi_srivastava22
Active Contributor
0 Kudos

Hi Evgeniy,

Thanks for the suggestion. I have already used the loop and tried the same as suggested by you earlier but its failing as there are blank values in the queue.I tried adding mapwithdefault function to pass "0" and tried using the loop again but it is not working.

PFB the screenshot, which might help you to understand the issue which I am trying to express -

Please suggest.

Thanks,

Nidhi Srivastava

manoj_khavatkopp
Active Contributor

Try this :

FYI : MapWithDeafult works when the source field does not appear , in your case it appears but with null value

for(int i=0;i<var1.length;i++)
{if(!(var1[i].equals("")))
{Double f=Double.parseDouble(var1[i]);
result.addValue(f);}
else
{result.addValue(var1[i]);}
}