题解 | #实现四舍五入#
实现四舍五入
https://www.nowcoder.com/practice/020a0cf673174d5795d97ae79cff59a0
#include <iostream> using namespace std; int main() { float num=0.0,num2=0.0; cin>>num; int num1=0; num1=(int)num; if(num<0) { num2=num1-0.5; if(num<num2) num1--; } else { num2=num1+0.5; if(num>num2) num1++; } cout<<num1<<endl; system("pause"); return 0; } // 64 位输出请用 printf("%lld")