cancel
Showing results for 
Search instead for 
Did you mean: 

validate negative values

Former Member
0 Kudos

Hello,

could you pelase help on how to set negative values in PI

my requirement is: i am getting input data for a filed TOTAL as 123456.78- now i want to set this negative value as prefix.

please let me know how to remove that postfix "-" and make it as prefix in mapping. my final output should be like -123456.78

thanks in advance...SARAN

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi SARAN

> my requirement is: i am getting input data for a filed TOTAL as 123456.78- now i want to set this negative value as prefix.

> please let me know how to remove that postfix "-" and make it as prefix in mapping. my final output should be like -123456.78

create simple UDF (Here input value is strVal)

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

Regards

Ramesh

Answers (2)

Answers (2)

former_member193376
Active Contributor
0 Kudos

You dont need a UDF..use node function "REPLACE WITH" and replace your"-" with a space and then just before sending it to the output you can concatenate "-" to the value.

Thanks

S

Former Member
0 Kudos

Adding to venkats comment..

you can use the below code to check whether value contains "-" to append the "-" prefix.

Parameter : strVal


 if(strVal.indexOf('-')!=-1) {
     return ("-"+strVal.substring(0,(strVal.length()-1)));
}else {
    return strVal;
}

You can also use Text function "endwith" to achieve this

Source + Constant -- > endWith --- > ifelse --> Target

Endwith will return boolean true or false. In the "then" constant(-) + source --> concat --> Then

Regards

Ramg

Former Member
0 Kudos

Hi Ram,

Thanks for the reply..as you given if i try to use the "endwith" function it returns value as " -123456.78- " but my requirement is "-123456.78". so plz let meknow how to remove " - " at the end of value.

Best Reagrds,

SARAN

Former Member
0 Kudos

Hi SARAN,

Use this code

create simple UDF (Here input value is strVal)

int len=strVal.length()-1;

if (strVal >0)

return strVal;

else

return ("-"+strVal.substring(0,len));

Regards

Ramesh

Former Member
0 Kudos

Hi Ramesh,

as i am new to this UDFs, could you pelase let me know what i have to specify at Arguments (type,name.javatype) and so ineed any imports for this UDF.

now if i copy your code in UDF editor, i am not able to run. it shows error as " cannot be applied to java.lang.String,int if (strVal >0) ^ 1 error"

i have selected radio button" value" and added name as "strVal".

Former Member
0 Kudos

hi Saran,

UDF:

Please use the suggested UDF in my earlier comment. It should work perfectly.

EndWith Function:

http://www.flickr.com/photos/51263811@N03/4711354049/

Regards

Ramg.

Edited by: Ramkumar Ganesh on Jun 18, 2010 4:52 PM

Former Member
0 Kudos

HI Ram, Thanks fo rthe reply. a small correction is required in your UDF.

when the input value given as " -12345.67" to your UDF, it returns as " --12345.67".

Former Member
0 Kudos

Hi SARAN

More simply.

Use

Constant ("-")----


>

Total -> replaceString("-" by "")-> concat--->Target-Total

Regards.

Former Member
0 Kudos

Use this...


 if(strVal.endsWith("-")) {
     return ("-"+strVal.substring(0,(strVal.length()-1)));
}else {
    return strVal;
}

Regards

Ramg