float类型不是精确的,系统会在后面加上随机数,所以不能用==或!=判断
判断方法如下
#include <string>
using namespace std;
int main()
{
float num=4.2;
if(num-4.2<=1e-6)
cout<<"A"<<endl;
else
cout<<"F"<<endl;
}
float类型不是精确的,系统会在后面加上随机数,所以不能用==或!=判断
判断方法如下
#include <string>
using namespace std;
int main()
{
float num=4.2;
if(num-4.2<=1e-6)
cout<<"A"<<endl;
else
cout<<"F"<<endl;
}