小编Ann*_*Ann的帖子

There are wrong answer when cout the long double value, C++

#include <iostream>
#include <iomanip>
#include <limits>

using namespace std;

int main() {
    const long double longDoublePI = 3.141592653589793238;
    cout << setw(16) << "longDoublePI = " << setprecision(numeric_limits<long double>::digits10 + 1) << longDoublePI << endl;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

But the result output is:

longDoublePI = 3.141592653589793116

Why the answer is wrong?

c++

2
推荐指数
1
解决办法
382
查看次数

标签 统计

c++ ×1