cancel
Showing results for 
Search instead for 
Did you mean: 

number need to be converted into string need UDF.

Former Member
0 Kudos

Hi Friends,

In my requirement number is coming with -ve sign on the right side of the number.

ie: if numberis -123.45 we are getting as 123.45- as client requirement.

Need to write an UDF to convert that number into string to map to string type element.

Thanks,

Swapna.

Accepted Solutions (0)

Answers (6)

Answers (6)

Former Member
0 Kudos

When you pass an element to UDF, it is passed as string only. So you do not need to convert it

UDF

String str1 = a.replace("-","");  // a is number to be operated
str1 = "-" + str1

return str1;

Former Member
0 Kudos

Hi,

you can use the below udf


public String replace(String a,Container container)
{
String c = a.substring(0,a.length());
String d = c + "-";
return d;
}

Former Member
0 Kudos

Hi Swapna,

it can done using substring and concat function

by using the substring try to eliminate the '-ve' sign then concat teh output with the

'-ve' sign

eg: -123.45 123.45 concat -ve

regards

Sampath

Former Member
0 Kudos

Hi,

you say your input could be for example 123.45- and your output:

1) should be a string

2) look like -123.45

3) 1 + 2

Could you please clarify.

Regards

Patrick

former_member518917
Participant
0 Kudos

Hi,

In udf write:

{

return a.substring(1,a.length())+"-";

}

adding empty string "" converts it into string.

Edited by: Ritu Sinha on Oct 14, 2008 1:59 PM

prateek
Active Contributor
0 Kudos

U can write a UDF with the following code

int i = -123.45;

String s = i + "";

OR

Directly use graphical mapping function,

Source filed -> replaceAll (provide argument as "-") -> Then concat "-" at end.

Regards,

Prateek