PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework
Re: Banker's Rounding by default, a big mistake !!
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework
Re: Banker's Rounding by default, a big mistake !!
![]() |
Re: Banker's Rounding by default, a big mistake !! |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
BTW, for financial calculation you better use the decimal type and forget about float and double
-- "A preoccupation with the next world pretty clearly signals an inability to cope credibly with this one." <FrankVDL@gmail.com> wrote in message news:1125611609.010997.194970@g47g2000cwa.googlegroups.com... > > Check the following example: it's a simple presentation of a ticket. > > > double[] lines = new double[5]; > > //Set some VAT's > lines[0] = 1.245; > lines[1] = 1.246; > lines[2] = 1.241; > lines[3] = 1.275; > lines[4] = 1.255; > > > //Print and calc total > double tot = 0; > foreach (double val in lines) { > tot += val; > Console.WriteLine(" {0:0.00}", val); > } > Console.WriteLine("-----"); > Console.WriteLine(" {0:0.00}", tot); > > > Console.ReadLine(); > > > This is the result : > > > 1,25 > 1,25 > 1,24 > 1,28 > 1,26 > -------- > 6,26 > > > Now take our your calculator (or excell if you like) an add the 5 lines > > manualy ! > > > Your result wil be 6.28. -> 0.02 difference !!!!!!!!! > > If I give this ticket to a client he demands to now where the 0.02 euro > has gone to. > > I know this has to do with the way C# round's its doubles (it is using > the Banker's Rounding method) > > What i don't understand is why it's the default. > > To put it simple : > How do I explain to someone (that is not a computer wiz), > that 1 + 1 = 1.1 ???? > > > Kind Regards > Frank Vanderlinden > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

