cancel
Showing results for 
Search instead for 
Did you mean: 

UDF to handle + or - in string and divide

Former Member
0 Kudos


Hi Experts ,

      i need a udf to do the handle the following 3 types of data

  Data of the below 3 types can come , i need to remove + or - if any , divide it by 100 and then add + /- based on the input data type ..

  100-   = needs to convert to 1-

  500+ = needs to convert to 5+

  2000 = needs to convert to 20

Please suggest probable UDF . String length can vary .

Thanks and Regards,

Arnab

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Arnab

Create an UDF like below

UDF

Execution type all values of a context

Input will be inputstr

code :

String newstr ="";

  if(inputstr[0].indexOf("-") != -1 )

  {

  newstr = inputstr[0].replaceAll("-","");

  newstr = Integer.toString(Integer.parseInt(newstr)/100)+"-";

  }

  else if(inputstr[0].indexOf("+") != -1 )

  {

  newstr = inputstr[0].replaceAll("\\+","");

  newstr = Integer.toString(Integer.parseInt(newstr)/100)+"+";

  }

  else

  {

  newstr= inputstr[0];

  newstr = Integer.toString(Integer.parseInt(newstr)/100);

  }

  resultAddvalue(newstr);

Former Member
0 Kudos

Hello,

U can use a combination of UDF and standard fucntions

UDF

Execution type all values of a context

Input will be var1

and add two Result type parameters result1 and result2


int len = var1[0].length();

String last = var1[0].substring(len-1,len);

if(last.equals("-") || last.equals("+"))

{

result1.addValue(var1[0].substring(0,len-1));

result2.addValue(last);

}

else

{

result1.addValue(var1[0]);

result2.addValue("");

}

Mapping:

Thanks

Amit Srivastava

0 Kudos

it's very simple by using standard function and also possiable by suing Udf ..

in below print screen , i took in put parameter is date for example .

input paramater -> replace string with (sign) -> devide by 100 -> round the value (if we get decimals) -> concat with symbol -> output parameter

thanks,