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;//三位小數

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM