PC Review


Reply
Thread Tools Rate Thread

Re: Banker's Rounding by default, a big mistake !!

 
 
Lloyd Dupont
Guest
Posts: n/a
 
      2nd Sep 2005
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."

<(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
>
> 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
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
By mistake I altered the Blank Document - how to restore default? SuannH Microsoft Word Document Management 1 13th Feb 2010 11:35 PM
Banker's Rounding - need help! Somecallmejosh Microsoft Excel Misc 3 20th Jan 2005 10:53 PM
Banker's Rounding in Excel DocShock Microsoft Excel Misc 8 23rd Apr 2004 10:58 AM
Changed font default by mistake =?Utf-8?B?Sm9hbm1hcnk=?= Microsoft Word Document Management 1 18th Apr 2004 11:11 PM
Rounding default Microsoft Excel Setup 0 26th Feb 2004 09:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:31 PM.