C C++输出语句printf()输出保留小数点后保留1,2,3,4,5,6,7..n位(默认四舍五入)

版权声明:转载请声明原文链接地址,谢谢! https://blog.csdn.net/weixin_42859280/article/details/84839726

基于Dev-C++ 5.11版本!
)
代码:

#include<iostream>
 using namespace std;
 int main()
 {
 printf("%f\n",10.0/3);
 printf("%0.1f\n",10.0/3);
 printf("%0.2f\n",10.0/3);
 printf("%0.3f\n",10.0/3);
 printf("%0.4f\n",10.0/3);
 printf("%0.5f\n",10.0/3);
 printf("%0.6f\n",10.0/3);
 printf("%0.7f\n",10.0/3);
 }

输出情况:

3.333333
3.3
3.33
3.333
3.3333
3.33333
3.333333
3.3333333

--------------------------------
Process exited after 0.7959 seconds with return value 0
请按任意键继续. . .

图片实例!
在这里插入图片描述
默认是小数点之后保留6位!

猜你喜欢

转载自blog.csdn.net/weixin_42859280/article/details/84839726