cancel
Showing results for 
Search instead for 
Did you mean: 

UDF to convert 163.63- to -163.63

Former Member
0 Kudos

Hi All,

The incoming field in XI is 163.63-

I need to write a UDF to covert the string to -163.63.

How do I write the same..

XIer

Accepted Solutions (1)

Accepted Solutions (1)

former_member214364
Active Contributor
0 Kudos

Hi Xler,

Here i am giving UDF code, This outputs positive value(163.63) if input value is positive (163.63)

and negative value as -163.63 if input is 163.63

Just create <b>Value</b> UDF by passing filed which contains this value as input

if(a.endsWith("-"))

{

a = a.replace('-',' ');

a = "-" + (a.trim());

return a;

}

else

return a;

Please let me know if there are any issues regarding this code.

Cheers,

Jag

Answers (2)

Answers (2)

justin_santhanam
Active Contributor
0 Kudos

XIer,

Please follow the code.

import java.util , in or udf import parameters. Conisder input as ur argument name.


		int cnt =input.indexOf("-");
		String result="";	
		if(cnt ==-1)
		{
		return ""+input+"";
		}
		else
		{
			StringTokenizer st = new StringTokenizer(input,"-");
			result = "-"+st.nextElement().toString();
			return ""+result+"";
		}

-raj.

justin_santhanam
Active Contributor
0 Kudos

XIer,

Do u want to use them inside ur program after converting into negative value or just passing to the target system. Also only u need to convert if you have the negative symbol on the end or for all the value.

Example:

189.90- then convert to -189.90

134.50 then the value must be 134.50 ,

Is my above understanding is correct?

-raj.