我尝试按如下方式打印十进制类型的最小值和最大值:
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
但根据文件
“十进制类型的范围更小,但精度高于双倍”
输出看起来如此吗?
答案 0 :(得分:1)
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
然而,为双重做同样的事。
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的范围比小数范围大约280个数量级(或10 ^ 280)