[Mono-list] Maths
Fergus Henderson
fjh@cs.mu.oz.au
Tue, 10 Feb 2004 05:23:53 +1100
On 09-Feb-2004, Jochen Wezel <jwezel@compumaster.de> wrote:
> Has anybody seen that behaviour yet which is produced by MS .Net?
>
> When rounding doubles to integer, there is a rounding error:
> Console.WriteLine(Convert.ToInt32(1.5)) 'is 2 - should be 2
> Console.WriteLine(Convert.ToInt32(2.5)) 'is 2 - should be 3
What makes you think that is an error?
The MS docs say "If value is halfway between two whole numbers, the even
number is returned; that is, 4.5 is converted to 4, and 5.5 is converted
to 6.". So this is behaving as intended.
If you want System.Math.Floor(Num + 0.5), then you know where to find it :)
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.