Interesting behaviour of type "decimal" in C#

Viewed 3488

If we declare padding as const decimal, the padding is not working.

mymoney = 1.2 and your money = 1.20, how can this behavior be explained?

class Program
{
    static void Main(string[] args)
    {
        decimal balance = 1.2m;

        const decimal ConstPadding = 0.00m;

        decimal padding = 0.00m;
        decimal mymoney = decimal.Round(balance + ConstPadding, 2);
        decimal yourmoney =  decimal.Round(balance + padding, 2);

        Console.WriteLine(mymoney); // 1.2
        Console.WriteLine(yourmoney);  //1.20
    }
}
5 Answers
Related