HJ7 取近似值 | 杂乱无章的初级程序员的题解
取近似值
https://www.nowcoder.com/practice/3ab09737afb645cc82c35d56a5ce802a
"IEEE 754 round-to-nearest-even",需要手动对小数部分进行判断
#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
int main()
{
float f;
cin >> f;
float intpart, fractpart;
fractpart = modff(f, &intpart);
cout << fixed << setprecision(0) << ((fractpart >= 0.5f) ? (intpart + 1.0f) : intpart) << endl;
}
#华为机试#