Skip to Content
0
Former Member
Apr 22, 2009 at 07:07 PM

BigDecimal UDF Help

259 Views

Hi all,

I have a requirement for a UDF:

Should be of type Context:

a (Amount goes here from source)

b (Posting Key goes here from source)

Result list: Goes to Target Amount

Below is my current code:

for(int x = 0;x<a.length;x++){

if (b[x].equalsIgnoreCase("50")){

float m = Float.parseFloat(a[x]);

Float n = new Float(m);

if (m > 0){

Float q = new Float(-1.0);

float r = n.floatValue() * q.floatValue();

Float s = new Float(r);

result.addValue(s.toString());

}

else {

result.addValue(a[x]);

}

}

else if(b[x].equalsIgnoreCase("40")){

float m = Float.parseFloat(a[x]);

Float n = new Float(m);

if (m > 0){

result.addValue(a[x]);

}

else {

Float q = new Float(-1.0);

float r = n.floatValue() * q.floatValue();

Float s = new Float(r);

result.addValue(s.toString());

}

}

}

All it does it that if posting key = 50 and amount is > 0 then it multiplies by -1 and adds to result list or if < 0 then adds straight to result list. If posting key is 40 and amount is > 0 then it adds straight to the results or finally if its < 0 then again multiplies by -1.

Problem is that due to PI having issues with Floats and even though I have applied the SAP note for BigDecimal, I still get erroneous values coming out on large amounts.

I'm not great at Java and have tried to implement using the BigDecimal Class and its methods to no success (get various compilation errors)

Please could someone re-write the above UDF but not using Floats but rather BigDecimal??

I'm sure anyone with half decent skills in Java can do this in no time!

Many thanks in advance,

Saqib.