xingd.net

.net related techonology

导航

.NET数值类型的精度

Posted on 2005-01-28 19:17  xingd  阅读(872)  评论(0)    收藏  举报

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.