[英]How to convert decimal scientific notation float/double to normal string
[英]Convert string represented in scientific notation to float and double
因此,我正在从事这个项目,我必须读取一个CSV文件,该文件包含以科学计数法表示的数字。 到目前为止,我要读的是每个数字,然后将该数字转换为字符串,然后使用stringstream将其转换为双精度,但是我不确定这是否是正确的方法。 任何建议/建议都会有所帮助!
double temp;
istringstream in(line); //line is the string which contains the number, ex: 3.30144800e+03
in >> temp;
arr[w++] = temp;
您可以使用std::atof
将字符串转换为双std::atof
istringstream in(line);
double value(atof(in.str().c_str()));
或者,您可以简单地将双精度流从缓冲区中流出来...
double value;
in >> value;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.