1 1 //强制类型转换 2 2 // https://blog.csdn.net/chaipp0607/article/details/54834954 3 4 double x; 5 int y1,y2; 6 scanf("%lf",&x); 7 y1=int(x); 8 y2=int(round(x)); 9 printf("%d ",y1); 10 printf("%d ",y2); 11 /* 12 5.9 13 5 14 6 15 */
1 scanf("%lf",&x); 2 int m=x; 3 cout<<m<<endl; 4 5.7 5 5 6 5.2 7 5 8 想几舍x入最简单的办法是在原数上加个1-0.x就可以了, 9 如:想四舍五入就—— 5.4 int(5.4+0.5)=5 10 5.5 int(5.5+0.5)=6 11 又如:想二舍三入就—— 5.2 int(5.2+0.7)=5 12 5.3 int(5.3+0.7)=6
1 3+0.5 会自动转换成double 2 int a; 3 ll b; 4 a+b //自动换为ll