且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

怎么比较双?

更新时间:2023-12-03 20:27:16

强制性链接:每个计算机科学家应该知道的关于浮点运算的内容 [ ^ ]。


在您阅读Carlo发布的文章后 - 了解浮点问题...

使用十进制 [ ^ ] ...

After you read the article Carlo posted - and understood the floating point problem...
Use Decimal[^]...
for ( decimal x = 0; x <= ( decimal )1; x += ( decimal )0.1 )
{
    Debug.WriteLine ( x.ToString ( ) );
    if ( x == ( decimal )1 )
        Debug.WriteLine ( "Equal" );
}