Output c# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Output c#

I saw this code on c# interview questions. I thought the output will be 7 and 12 but the truth is the output will be 6 and 12. Why is that? public class Program { public static void Main(string[] args) { Console.WriteLine(Math.Round(6.5)); Console.WriteLine(Math.Round(11.5)); } }

20th May 2017, 9:19 PM
Sagheb
Sagheb - avatar
1 Answer
+ 4
Math.round (c#) runs on something called bankers rounding: "The integer nearest a. If the fractional component of a is halfway between two integers, one of which is even and the other odd, then the even number is returned."
20th May 2017, 9:34 PM
Rrestoring faith
Rrestoring faith - avatar