Practice mode C#

What does Console.WriteLine(Math.Round(2.5)); print in C#?

Correct answer A. 2

Explanation

Math.Round with no mode uses MidpointRounding.ToEven, also called banker's rounding: a value exactly halfway between two integers goes to the even one. So 2.5 rounds to 2 and 3.5 rounds to 4. This reduces bias when many values are rounded. To get school-style rounding, call Math.Round(2.5, MidpointRounding.AwayFromZero), which returns 3.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.