Possible Duplicate:
.Net Round Bug
In C#: Math.Round(2.5) result is 2 (instead of 3)! Are you kidding me?
Code:
var d1 = Math.Round(187.5); // 188
var d2 = Math.Round(62.5); // 62
Why is it so?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
By default,
Math.Rounduses a form of rounding called Banker’s Rounding, which rounds to the nearest even integer when the input is halfway between two integers.See Why does .NET use banker’s rounding as default? for an understanding of this design decision.
If you don’t like this behaviour, you can always use this overload of
Math.Round, which lets you specify theMidPointRoundingMode(ToEven, AwayFromZero).