如何在 C++ 中使用 cout 以全精度列印雙精度值?
輸出流 cout 允許使用一些運算元,你可以直接在 cout 上設定精確度並使用固定格式說明符。要獲得雙精度的全精度,你可以使用 limits 庫。例如,
示例
#include<iostream>
#include <limits>
using namespace std;
int main() {
// Get numeric limits of double
typedef std::numeric_limits< double > dbl;
double PI = 3.14159265358979;
cout.precision(dbl::max_digits10);
cout << "Pi: " << fixed << PI << endl;
return 0;
}輸出
這將給出以下輸出 -
3.14159265358979
廣告
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP