No you can't change the default behavior.

From: [email protected] [mailto:[email protected]] On 
Behalf Of Michael Minutillo
Sent: Wednesday, June 16, 2010 9:33 PM
To: ozDotNet
Subject: Re: Math.Round

Interestingly

Math.Round(double, int) and Math.Round(double, MidpointRounding) are both 
overloads of Math.Round(double, int, MidpointRounding) which is managed code. 
Unfortunately you cannot change the default MidpointRounding rule it is 
hardcoded as ToEven.

Math.Round(double) is actually a call to an unmanaged API. Its behavior is 
hardcoded into the internals of the framework and I have no idea what it does 
and how to control it.

Odd.

On Thu, Jun 17, 2010 at 12:24 PM, Michael Minutillo 
<[email protected]<mailto:[email protected]>> wrote:
Hi Alastair,

As there is a business reason for this I'd consider writing a separate function 
to do it for you. Maybe make it an extension method. If you want to get crazy 
you could probably write a unit test to check for uses of Math.Round(..) and 
fail.

On Thu, Jun 17, 2010 at 12:19 PM, Alastair Waddell 
<[email protected]<mailto:[email protected]>> wrote:
Hi All,

Does anybody know if it is possible to change the default behaviour of
the math.round function.

Out of the box is does this;

Dim number = 98.5
Dim RoundedNumber = Math.Round(number)

RoundedNumber = 98

What I want is to change the behaviour to

Dim number = 98.5
Dim RoundedNumber = Math.Round(number, MidpointRounding.AwayFromZero)

RoundedNumber = 99

I would like my developers to not have to think about adding the Mode.


Now to save some of the arguments I KNOW we are going to have;

Yes - We could have code reviews to highlight when it is incorrect
Yes - FX Cop or similar
Yes - There are probably different / better algorithms
Yes - There are business reasons for this


So

My question is can we change the default behaviour from
Math.Round(number, MidpointRounding.ToEven)
To
Math.Round(number, MidpointRounding.AwayFromZero)



Alastair





Important Notice
This email contains information which is confidential and intended solely for 
the use of the individual or entity to whom it is addressed.  Please notify the 
sender immediately if you have received this e-mail by mistake and delete this 
email from your system.  If you are not the intended recipient, any form of 
distribution, copying or use of this communication or the information contained 
or attached is strictly prohibited.  Although Disability Services Commission 
has taken reasonable precautions to ensure no viruses are present in this 
email, the Commission cannot accept responsibility for any loss or damage 
arising from the use of this email or attachments.



--
Michael M. Minutillo
Indiscriminate Information Sponge
Blog: http://wolfbyte-net.blogspot.com



--
Michael M. Minutillo
Indiscriminate Information Sponge
Blog: http://wolfbyte-net.blogspot.com

Reply via email to