cancel
Showing results for 
Search instead for 
Did you mean: 

Rounding the values in SAP PI/PO

sateesh437
Participant
0 Kudos

Hi Experts,

We are facing an issue with rounding the values, please help.

Example:

Incoming valuesRounding
90.909190.9
90.909190.9
90.909190.9
90.909190.9
90.909190.9
90.909190.9
90.909190.9
90.909190.9
90.909190.9
90.909190.9
90.90990.9
1000999.9

After Rounding Sum is not matching....!

In some scenarios if we round for 2 decimals it works and in some it will work with 3 decimals.

Please help me in achieving this in a generic way.

Thanks in advance..!

Regards,

Sateesh.    

Accepted Solutions (0)

Answers (1)

Answers (1)

GauravKant
Contributor
0 Kudos

HI Sateesh,

If you are rounding value for 2 or 3 decimal the accuracy will be quite close to total.

after rounding the value it will vary by .1 or .01 or .001 something like depending upon decimal value.

For accurate sum value round the value till 4 digit as per you example.

Use FormatNum funtion for the same.


Regards,

Gaurav

sateesh437
Participant
0 Kudos

Hi Gaurav,

Thanks for your reply..!

As per requirement, we can Format the Number to 3 decimals only.

Regards,

Sateesh.

GauravKant
Contributor
0 Kudos

Hi Sateesh,

You can try to add all the incoming value before rounding then round the sum and pass it to target.

Hope it will match the sum value.

Regards,

Gaurav

sateesh437
Participant
0 Kudos

Hi Gaurav,

We will be receiving individual values(with more than 4 decimals) and rounding to decimal(max to 3) then sending the individual values to SAP, Sum will be calculated at ECC end.

Regards,

Sateesh.

former_member190293
Active Contributor
0 Kudos

Hi Sateesh!

You should keep in mind that there will always be the cases when your rounded sum differs from original sum.

One of approaches is to check both of your sums and in case of difference split the difference to minimal values and add it one by one to your rounded values.

3.3334+3.3334+3.3332=10

3.333+3.333+3.333=9.999

3.333(+0.001)+3.333+3.333=10

Regards, Evgeniy.

sateesh437
Participant
0 Kudos

Hi Evgeniy,

We tried this solution by using UDF, here the problem is when we didn't get value from source then it throwing error at UDF as value of an array can't be null/empty.

Regards,

Sateesh.

GauravKant
Contributor
0 Kudos

Hi Sateesh,

One alternate to this could be to use FixValues, where you can set  empty value as source and target as "0".

incomingvalue--fixvalue---UDF--terget

Regards,

Gaurav

former_member190293
Active Contributor
0 Kudos

I guess it's not a problem in java to add the code for handling such situations or to catch this exception and return values accordingly.

Regards, Evgeniy.