Dan*_*son 1 c++ precision c++11 c++14
如果我有一个等于的双字符串"123.546123"并将其转换为double atof,我只得到123.546.我该怎么做才能解决这个问题?
这是我的代码:
#include <iostream>
int main(){
std::string a = "123.546123";
double b = atof(a.c_str());
std::cout << a << std::endl;
std::cout << b << std::endl;
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
std::cout默认情况下,打印精度为6的浮点值.为了增加精度,使用std::setprecision从<iomanip>,例如:
std::cout << std::setprecision(9) << b << std::endl;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
312 次 |
| 最近记录: |