cancel
Showing results for 
Search instead for 
Did you mean: 

Message Mapping:: Java Function issue

Former Member
0 Kudos

we have PI7.1 SPS 07 & JDK version as JDK15.

I am using following program to calculate the Total of payments ( Put constants so it would be easy for others to test in their ESR )-->

**********************************************************************************************

BigDecimal sum = new BigDecimal("0.00");

BigDecimal bd = new BigDecimal("144.44");

BigDecimal hund = new BigDecimal("100");

for(int i=0;i<3028;i++)

{

sum = sum.add(bd);

}

//sum=sum.divide(hund);

String res=sum.toString();

result.addValue(res);

**********************************************************************************************

(Expression) 3028 * 144.44 = (CalculatorResult)437364.32 -


(PI Code result)437364.30

(Expression) 947 * 144.44 = (CalculatorResult)136784.69 -


(PI Code result) 136784.68

With numbers like 1347, 1047 etc I got difference of 1 Cent ( so like to call them as Magic numbers here). But numbers like 1119, 3026, 3027, 3028, 1100 etc give correct results.

One of my friend executed the same code in his Java environment & got correct results with magic numbers too with no 1 cent of difference.

Can you pls. test the same code in your environment & share the result and if it provides correct result then pls. share version of your JAVA environment too.

Thanks

Lalit

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

I have not tried this on my system but you can add this to roundoff the value upto 2 decimal places..

e.g.

sum= sum.divide(hund, 2, BigDecimal.ROUND_FLOOR);
or
sum = sum.multiply(hund, 2, BigDecimal.ROUND_FLOOR);

put the correct variables as per your need in above examples.

Former Member
0 Kudos

Sarvesh

I have to use the ADD function only, as I need to sum the payments made in whole context & queues.

I left the "hund" variable because I even tested following -->

Multiplied the number by 100 to remove the decimal places

Add them together "magic number" times

Multiplied result with 100

But still got the difference of 1 cent.

I will appreciate if you can execute the code given by me in you environment, you have to import java.math.BigDecimal

Former Member
0 Kudos

I have tested the same code in my PI7.1 -- SP07 and got the result as 437364.32

Former Member
0 Kudos

Sarvesh

You are getting the correct result that means, can you pls. share what JAVA & JDK version you have installed in PI server.

Former Member
0 Kudos

On PI under ESR Help menu we have Java version: 1.6.0_17 because in my pc I have installed java version 1.6.0_17.

Edited by: Sarvesh Singh on Feb 4, 2010 1:11 AM

Former Member
0 Kudos

Thanks Sarvesh

Issue resolved. Actually my code was perfectly fine, what I didn't notice is that after using this function there was one more function used to do the Justification of spaces as I am converting a XML into fixed length TEXT file.

And in that another function I was using FLOAT which was the actual culprit & doing the round-off. Change it to String & everything is fine now.

Thanks for quick responses, I appreciate that.

Former Member
0 Kudos

Good to know that.

Note: It is always good to use display queue on each function to see the resutls in each step rather checking the end result directly.

Regards,

Sarvesh

Answers (0)