By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,694 Members | 1,795 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,694 IT Pros & Developers. It's quick & easy.

System.Math.Round bug

P: n/a
Hopefully I'm just missing something obvious, but this method (or more
likely the CLR/complier) has a bug where I can not use the overloaded
version:
Round( double value, int digits )

It always seems to use the Round(decimal value, int decimals) version, no
matter what the first parameter is - double or decimal. Intellisense agrees
with the compiler - incorrectly.

Is it me, a known issue or a new issue? I need this quite desparately; I do
have a workaround where I check the scale of the number and do fancy stuff
assuming it will Round to decimal places rather than digits but its just too
ugly to bear wth for long.

TIA

Radek
Oct 12 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Radek Cerny <ra*********@nospam.c1s.com.auwrote:
Hopefully I'm just missing something obvious, but this method (or more
likely the CLR/complier) has a bug where I can not use the overloaded
version:
Round( double value, int digits )

It always seems to use the Round(decimal value, int decimals) version, no
matter what the first parameter is - double or decimal. Intellisense agrees
with the compiler - incorrectly.

Is it me, a known issue or a new issue? I need this quite desparately; I do
have a workaround where I check the scale of the number and do fancy stuff
assuming it will Round to decimal places rather than digits but its just too
ugly to bear wth for long.
Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

If you compile the following code and then look at it in Reflector or
ILDASM, I think you'll see it calling the right one:

using System;

class Test
{
static void Main()
{
double d = 0.2;
Console.WriteLine (Math.Round(d, 2));
}
}
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Oct 12 '06 #2

P: n/a
Hi Radek,

yes you're missing something (not very) obvious, the intellisense doesn't
always show you the right overload. But i'm sure it is using the right. You
could check it with ildasm.
Is there, beside the intellisense another reason you think it's chosing the
wrong overload?

PS. You should better read the link, Jon gave you. This certanly is a case
where the Gui is superfluous. You could show the problem in simple Console
app with only one method.

"Radek Cerny" <ra*********@nospam.c1s.com.auschrieb im Newsbeitrag
news:eg**************@TK2MSFTNGP04.phx.gbl...
Thanks Jon,

Demo Attached.
Definitely a bug; forgot to mention using .Net 2

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP************************@msnews.microsoft.c om...
>Radek Cerny <ra*********@nospam.c1s.com.auwrote:
>>Hopefully I'm just missing something obvious, but this method (or more
likely the CLR/complier) has a bug where I can not use the overloaded
version:
Round( double value, int digits )

It always seems to use the Round(decimal value, int decimals) version,
no
matter what the first parameter is - double or decimal. Intellisense
agrees
with the compiler - incorrectly.

Is it me, a known issue or a new issue? I need this quite desparately;
I do
have a workaround where I check the scale of the number and do fancy
stuff
assuming it will Round to decimal places rather than digits but its just
too
ugly to bear wth for long.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

If you compile the following code and then look at it in Reflector or
ILDASM, I think you'll see it calling the right one:

using System;

class Test
{
static void Main()
{
double d = 0.2;
Console.WriteLine (Math.Round(d, 2));
}
}
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too



Oct 13 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.