相关疑难解决方法(0)

为什么C#System.Decimal会记住尾随零?

有没有理由C#System.Decimal记得它输入的尾随零的数量?请参阅以下示例:

public void DoSomething()
{
    decimal dec1 = 0.5M;
    decimal dec2 = 0.50M;
    Console.WriteLine(dec1);            //Output: 0.5
    Console.WriteLine(dec2);            //Output: 0.50
    Console.WriteLine(dec1 == dec2);    //Output: True
}
Run Code Online (Sandbox Code Playgroud)

小数被归类为相等,但是dec2会记住它是以额外的零输入的.这是什么原因/目的?

c# precision decimal

18
推荐指数
1
解决办法
1566
查看次数

标签 统计

c# ×1

decimal ×1

precision ×1