TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Dave
NA
161
0
Math.Round()
Apr 29 2008 5:02 AM
Hi all,
I knocked up a quick program to divide marks by 2. I wanted to round to 2 decimal places. My code is:
static void Main(string[] args)
{
double a, b;
Console.Write("Enter mark:");
a = double.Parse(Console.ReadLine());
while (a != -1)
{
b = a / 2.0;
b = Math.Round(b, 2, MidpointRounding.AwayFromZero);
Console.WriteLine(b + "\n");
Console.WriteLine("Enter mark:");
a = double.Parse(Console.ReadLine());
}
Console.ReadLine();
}
The thing that I do not get - when I enter 36.05, it outputs 18.02. Now, 36.05 / 2.0 equals 18.025. So my question is, why doesn't Math.Round successfully round that up to 18.03?
There's no hassle or rush on this. It is just a point of curiosity for me. I don't like it when I cannot figure out why I don't get an expected result.
Cheers
Reply
Answers (
2
)
Problem using webclient : (illegal characters in Path) error
How to convert to Upper case the text you are typing in the text box?