float类型占32bit空间,只有7位精度,下面的程序
public class FloatPrecision
{
public static void Main()
{
Console.WriteLine((int)123456789F);
}
}
输出结果为123456792.
double占64bit空间,15~16位精度,下面的程序
public class DoublePrecision
{
public static void Main()
{
Console.WriteLine((long)123456789012345678D);
}
}
输出结果为123456789012345680
decimal占128bit空间,28位精度,MSDN中描述如下:
This type is useful for applications (such as accounting) where rounding errors must be avoided.
.NET数值类型的精度
80酷酷网 80kuku.com