drf21989 2016-02-09 09:53
浏览 134
已采纳

PHP中科学记数法的数字不正确

I'm reading data from spreadsheets that contain long numeric ID strings. I'm trying to make my system foolproof by making sure that the data reads correctly even if the column format is incorrectly set as a number.

So the spreadsheet contains the number 32486509223273700000 in scientific notation as 3.2486509223274E+19. Before i store it as a string i need to convert it to the original value. This is where the problems come in.

I can't make PHP convert the scientific notation back to the original number. Using various methods for converting the number back to original, it always seems to have different digits instead of trailing zeros.

$i = 3.2486509223274E+19;
echo $i; //32486509223274000384
echo number_format($i,0,'',''); //32486509223274000384
echo sprintf('%0.0f', $i); //32486509223274000384

Please note that I intend to store the end result as a string.

  • 写回答

3条回答 默认 最新

  • dongshan1811 2016-02-09 10:27
    关注

    Note that the double floating point format has a precision of about 15.5 decimals. All other displayed decimals are extrapolated. And as always, extrapolation is a dangerous game.

    Or in other words, 3.2486509223274E+19 represents an interval, roughly from 3.24865092232739984E+19 to 3.24865092232740024E+19. Any integer in that interval has to count as "correct" extrapolation.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog