C# ubuntu上的dotnet十进制测试
我尝试打印十进制类型的最小值和最大值,如下所示:C# ubuntu上的dotnet十进制测试,c#,C#,我尝试打印十进制类型的最小值和最大值,如下所示: decimal decmin = decimal.MinValue; decimal decmax = decimal.MaxValue; Console.WriteLine($"The range of the decimal type is: {decmin} and {decmax}"); The range of the decimal type is: -79228162514264337593543950335 and 79228
decimal decmin = decimal.MinValue;
decimal decmax = decimal.MaxValue;
Console.WriteLine($"The range of the decimal type is: {decmin} and {decmax}");
The range of the decimal type is: -79228162514264337593543950335 and 79228162514264337593543950335
结果如下:
decimal decmin = decimal.MinValue;
decimal decmax = decimal.MaxValue;
Console.WriteLine($"The range of the decimal type is: {decmin} and {decmax}");
The range of the decimal type is: -79228162514264337593543950335 and 79228162514264337593543950335
但是根据文件
“decimal类型的范围比double小,但精度更高”
输出看起来是这样吗
Console.WriteLine($"The range of the decimal type is: {decimal.MinValue} and {decimal.MaxValue}");
// The range of the decimal type is: -79228162514264337593543950335 and 79228162514264337593543950335
这是-7.9228162514264337593543950335E+28和7.9228162514264337593543950335E+28
但是,对double也一样
Console.WriteLine($"The range of the double type is: {double.MinValue} and {double.MaxValue}");
// The range of the double type is: -1.79769313486232E+308 and 1.79769313486232E+308
所以你看,double的范围大约比decimal的范围大280个数量级(或10^280)是的。你认为不会吗?你真正的问题是什么?在我看来,它的范围比doubleDouble可以达到1.7E308的范围更大。我认为这些数字要少得多。小数点到7.9E28,所以它的范围不到一个双精度的十分之一。