【发布时间】:2013-07-04 12:28:43
【问题描述】:
我有一个包含数字读数的文件(例如 5.513208E-05 / 1.146383E-05) 我读取文件并将条目存储在临时字符串中。 之后,我将临时字符串转换为浮点变量(我将其存储在多维数组中)。 我使用下面的代码进行转换。
getline(infile, temporary_string, ',');
Array[i][0] = ::atof(temporary_string.c_str());
getline(infile, temporary_string);
Array[i][1] = ::atof(temporary_string.c_str());
问题是当我将浮动打印到屏幕上时
5.51321e-05 1.14638e-05 代替 5.513208E-05 1.146383E-05
我怎样才能得到存储的精确数字???
【问题讨论】:
-
Array的变量类型是什么?如果它是浮动的,请尝试将其更改为双精度。 -
嗯,
float会给你大约 log10(2^23) 位,即“6.92”,所以介于 6 到 7 位之间。 -
点击此链接可能会对您有所帮助stackoverflow.com/questions/10605653/…
-
浮点数不精确。在 32 位系统上,
float的 6 个有效数字的精度是正常的。