cpp保留任意小数点位数

一、保留有效数字的问题

1 #include<iostream>
2 #include<iomanip>
3 #include "stdlib.h"
4 using namespace std;
5 int main(){
6     double PI=3.1415926;
7     cout<<setprecision(3)<<PI<<endl;
8     return 0;//3.14三位有效数
9 }

二、保留有效数字

1  cout<<setiosflags(ios::fixed)<<setprecision(3)<<ans<<endl;//三位小数
原文地址:https://www.cnblogs.com/h404nofound/p/12233996.html