如何使用 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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP