Shunpower @ 2021-11-14 00:27:40
RT,在做大模拟,眼看要 AC 结果被精度拍死。
代码如下:
#define S setiosflags(ios::fixed)<<setprecision(2)
cout<<S<<sum/(ld)(cntpass+cntfail)+eps<<endl;
其中sum/(ld)(cntpass+cntfail)的真实值为54.125,eps=1e-5,但是保留之后输出是54.12/ll
怎么使得输出54.13?
by Yusani_huh @ 2021-11-14 00:34:07
额,为什么 eps 要设成 1e-5 啊,如果你要四舍五入的话不是应该设成 5e-3 吗
by ud2_ @ 2021-11-14 00:42:19
long double 类型是能精确表示 54.125 的。
by FerventTemp0 @ 2021-11-14 01:33:54
四舍五入特判一下,C++ 用的向偶取整
by fzj2007 @ 2021-11-14 07:43:02
@LEMON_ni 你希望四舍五入还是什么啊?四舍五入显然要加0.005
by Heliox @ 2021-11-14 08:02:21
@LEMON_ni cmath头文件有round()函数
by Shunpower @ 2021-11-14 22:06:47
@fzj2007
我希望四舍五入保留两位数字。
by Shunpower @ 2021-11-14 22:15:56
感谢各位,破案了,我是傻子const int eps=1e-3……