C/C++输出保留n位小数

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/soeben/article/details/82708410

c 保留两位小数

#include <stdio.h>
int main(){
	printf("%0.2f",3.1415926);
}

c++ 保留两位小数

#include <iostream>
#include <iomanip>
using namespace std;
int main(){
	cout<<fixed<<setprecision(2)<<3.1415926<<endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/soeben/article/details/82708410