Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
long double m; cout << "enter double: "; cin >> m; cout << "m = " << m <<endl;
输入:
输入双:1.546640625
输出:
米 = 1.54664
我必须用点转换成二进制,当我读到像 2.359375000 这样的数字时
米 = 2.35938
它有效,但我认为问题是 1.546640625 中的零
您已经阅读了 double 的全部值。问题出在 cout 上。默认情况下,它会将值四舍五入到小数点后 6 位。
要设置精度 cout 使用,请使用setprecisionfrom <iomanip>:
setprecision
<iomanip>
#include <iostream> #include <iomanip> using namespace std; int main() { long double d; cin >> d; cout << setprecision(10) << d << endl; return 0; }