33,317
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
using namespace std;
int main()
{
double d=1.555;
int a=static_cast<int>(100*(d+0.005));
cout<<a%10<<endl;
system("pause");
return 0;
}
#include<iostream>
using namespace std;
int main()
{
double d=1.55;
int a=static_cast<int>(10*(d+0.05));
cout<<a%10<<endl;
system("pause");
return 0;
}
或者
#include<iostream>
#include "float.h"
using namespace std;
int main()
{
double d=1.555;
int a=static_cast<int>(100*(d+0.005 + FLT_EPSILON));
cout<<a%10<<endl;
system("pause");
return 0;
}
1)double 问题
把 double d=1.555;
该成
double d=1.5555;