方法一(也是常用方法): #include <cstdio> // C++程序中調用標准C的輸入輸出庫
using namespace std;
int main()
{ double d; d = 1.65469464; printf("%lf",d); // 保留默認的小數位(好像是6位) printf("%.3lf",d); // 指定保留三位小數
return 0; }
方法二: #include<iomanip> using namespace std; int main() { double d; d = 1.65469464; cout<<setprecision(3)<<std::fixed<<你的數據; // 指定保留三位小數 return 0; }