Rounding and loss of precision

S

ShikariShambu

Hi All,
I have an issue related with rounding and loss of precision that I can't
seem to figure. I am using System.Math.Round(decimal,2)

We have a financial systems that maintains the final data in hundredth
precision

When I do the calc the credit is off from debit by a penny
here is the rounded data
62358.9 1593.7
1547.03 62140.55
62358.9 171.69
171.69 62358.9
171.69
126436.52 126436.53


The raw data is in sync

62358.9025 1593.6975
1547.0281 62140.5475
62358.9025 171.6856
171.6856 62358.9025
171.6856
126436.5187 126436.5187


How can round the numbers such that i don't have the offset

TIA
 
P

Philip Rieck

You can't round data and not lose precision. However, you can wait to round
it to the end. Keep your data precise, and round during display if possible
(instead of using round to display it, you can use String.Format("{0:#0.00",
number), )

By waiting to round it until as late as possible, you will accumulate a much
smaller error then rounding immediately.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top