重複の可能性:
floatとfloatリテラルの比較での奇妙な出力
なぜdoubleとfloatを比較すると、予期しない結果が生じるのですか?
3.5
次のコードでは、デフォルトでC ++である必要があるため、答えが「等しくない」と予想していましdouble
たが、結果は「等しい」でした。
宣言float a=3.5f
との違いは何float a=3.5
ですか?
#include<iostream>
using namespace std;
int main()
{
float a=3.5;
if(a==3.5)
cout<<"equal"<<endl;
else
cout<<"Not equal"<<endl;
return 0;
}