Interesting behaviour of type “decimal” in C#

前端 未结 5 1033
遇见更好的自我
遇见更好的自我 2021-02-12 13:34

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 Progra         


        
5条回答
  •  南旧
    南旧 (楼主)
    2021-02-12 13:44

    balance + ConstPadding == balance
    

    Because ConstPadding is zero!

    You should -

    Console.WriteLine(yourmoney.ToString("0.00"));  //1.20
    

提交回复
热议问题