[英]how to maintain double's precision in C++ Visual studio 2008
main()
{
double d1 = 1234.1;
cout << "d1 = 1234.1 --> " << d1 << endl;
double d2 = 1234.099999;
cout << "d2 = 1234.099999 --> " << d2 << endl;
}
Output: 输出:
d1 = 1234.1 --> 1234.1
d2 = 1234.099999 --> 1234.1
How can I get the exact value for d2 ? 如何获得d2的确切值? Please suggest. 请提出建议。
Try 尝试
cout.precision(<number of digits after comma>);
like 喜欢
cout.precision(5);
before output statement. 在输出语句之前。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.