cancel
Showing results for 
Search instead for 
Did you mean: 

Minus Sign

Former Member
0 Kudos

Hi Group,

In designing I have one element with value 19- ,I need to conver it in to -19 ,

Can any body suggest how to do this using UDF.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi swabap,

best is to google with

java split array

if after the split

array.length = 1 --> no minus wa found

if

array.length = 2

then return = '-'+ arry[1].

Regards Mario

Regards Mario

Former Member
0 Kudos

Hi Group,

I am using the following code,when I am getting a<i> value negative like 19- its converting to -19 but its still failing.Can any bodyu suggest.

Here I am attaching the UDF code.


BigDecimal sum = new BigDecimal("0");
BigDecimal amt = new BigDecimal("0");

 for(int i=0;i<a.length;i++)
{
 
      if(a<i>.endsWith("-"))
    {
       a<i> = a<i>.replace('-',' ');
       a<i> = "-" + a<i>;
    }

     amt = new BigDecimal(a<i>);
     sum = sum.add(amt);  
   // sum = sum + Double.parseDouble(a<i>);

}
    result.addValue(String.valueOf(sum));

Former Member
0 Kudos

Try this:


BigDecimal sum = new BigDecimal("0");
BigDecimal amt = new BigDecimal("0");
 
 for(int i=0;i<a.length;i++)
{
 
      if(a<i>.endsWith("-"))
    {
       a<i> = a<i>.replaceAll("-","");
       a<i> = "-" + a<i>;
    }
 
     amt = new BigDecimal(a<i>);
     sum = sum.add(amt);  
   // sum = sum + Double.parseDouble(a<i>);
 
}
result.addValue(String.valueOf(sum));

Former Member
0 Kudos

HI,

Actually this is the same code which I posted,it is not working may be due to this statement ,where the BigDecimal function not returning the neagtive number.

Can any body Suggest.

<b> amt = new BigDecimal(a<i>);</b>

PS:In my earlier post In the code Part I have by mistake I typed <b>' > '</b>.

Former Member
0 Kudos

Hi swabap,

my posting it's not the same. Look closely. And it worked in my test scenario.

Regards

Dominic

Former Member
0 Kudos

Hi Dominic,

Thank you!its working fine.

Answers (2)

Answers (2)

Former Member
0 Kudos

First use the java function ReplaceString("originalString","replacement") on your value and replace the Minus with "". Then use concat your "old"value with the minus: valNew = "-".concat(valOld);

Hope this helps.

Dominic

udo_martens
Active Contributor
0 Kudos

Hi Swabap,

you can do that with standard function "substring". Plz have a look to <a href="http://help.sap.com/saphelp_nw04/helpdata/en/43/c4cdfc334824478090739c04c4a249/content.htm">Standard Functions</a>

Regards,

Udo