473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

System.Math.Round bug

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
2 5027
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ark | last post by:
Hi everyone, Does anyone know if Direct3D overloads System.Math functions? Also is it possible to access the base functions of the overloaded function (in other words restore original of the...
6
by: ng_mr | last post by:
No, not a question about "banker's rounding" or whatever it's called. I want to round a double to the nearest 100th, so I perform the following: // original is a double double result =...
1
by: nvphu | last post by:
I need to use the constant M_PI. So, I insert the directive # include <math.h>. However when compiled, there are errors : M_PI undeclared identifier. Second, I can not use the function...
4
by: Chris Davoli | last post by:
The folllowing will round to 526, but it should round to 527. It works correctly for all other numbers, except for this one. Does anybody know of a bug in Math.Round? Dim ldecWater As Decimal =...
10
by: David Coleman | last post by:
I am running VS 2003 and have applied SP1. (On WinXP SP2, .Net 1.1) In the Command Window I get the following ? Math.Round(0.715, 2) 0.72 ? Math.Round(0.725, 2) 0.72 ? Math.Round(0.735, 2)...
3
by: Altman | last post by:
OK I was having rounding problems before and I didn't realize that their was a third parameter in the round function that would tell it if it a 5 to round up. I thought adding this would fix the...
6
by: Zeng | last post by:
Math.Round has good behavior as following: Math.Round(3.45, 1); //Returns 3.4. The last '5' is thrown away because 4 is even Math.Round(3.75, 1); //Returns 3.8. The last '5' is used because '7'...
4
by: =?Utf-8?B?UmVuZQ==?= | last post by:
Hello everyone I have a problem with Math.Round, it´s ocurring some strange: Math.Round(12.985) = 12.98, it´s wrong. It should be: 12.99 Why?? What is the problem? Help ME !!!!
9
by: DaiOz | last post by:
Hi guys im doing a course which includes some JavaScript and I need help with the following question please, The code I have so far is below but I don't think its right please help as I need...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.