class Program {
static void Main(string[] args) {
double d = 120.5;
Console.WriteLine(Math.Round(120.5)); //121
Console.WriteLine(Math.Round(d)); // 120
}
}
When a variable is passed as an argument into Math.Round it produces an answer similar to Convert.ToInt32 where floating numbers are rounded off to the nearest even number if the trailing tenth number is 0.5.
Anyone can kindly explain? Thanks in advance.
Thanks for the answers! I use Replit most of the time, that's the output I got. But seeing the replies, I tested it again in VS and I got both 120. I guess there's a bug in replit? Kindly refer to attachments.