<bdo id='eWA2i'></bdo><ul id='eWA2i'></ul>

  • <i id='eWA2i'><tr id='eWA2i'><dt id='eWA2i'><q id='eWA2i'><span id='eWA2i'><b id='eWA2i'><form id='eWA2i'><ins id='eWA2i'></ins><ul id='eWA2i'></ul><sub id='eWA2i'></sub></form><legend id='eWA2i'></legend><bdo id='eWA2i'><pre id='eWA2i'><center id='eWA2i'></center></pre></bdo></b><th id='eWA2i'></th></span></q></dt></tr></i><div id='eWA2i'><tfoot id='eWA2i'></tfoot><dl id='eWA2i'><fieldset id='eWA2i'></fieldset></dl></div>
    1. <small id='eWA2i'></small><noframes id='eWA2i'>

      <tfoot id='eWA2i'></tfoot>

      <legend id='eWA2i'><style id='eWA2i'><dir id='eWA2i'><q id='eWA2i'></q></dir></style></legend>
      1. 显示不带科学计数法的浮点值

        时间:2023-10-31

            <tbody id='07F1W'></tbody>
          <i id='07F1W'><tr id='07F1W'><dt id='07F1W'><q id='07F1W'><span id='07F1W'><b id='07F1W'><form id='07F1W'><ins id='07F1W'></ins><ul id='07F1W'></ul><sub id='07F1W'></sub></form><legend id='07F1W'></legend><bdo id='07F1W'><pre id='07F1W'><center id='07F1W'></center></pre></bdo></b><th id='07F1W'></th></span></q></dt></tr></i><div id='07F1W'><tfoot id='07F1W'></tfoot><dl id='07F1W'><fieldset id='07F1W'></fieldset></dl></div>
            <bdo id='07F1W'></bdo><ul id='07F1W'></ul>
            <legend id='07F1W'><style id='07F1W'><dir id='07F1W'><q id='07F1W'></q></dir></style></legend>

              <tfoot id='07F1W'></tfoot>

                <small id='07F1W'></small><noframes id='07F1W'>

                  本文介绍了显示不带科学计数法的浮点值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  当我在 PHP 中进行以下乘法运算时:

                  When i make the following multiplication in PHP:

                  $ret = 1.0 * 0.000000001;
                  

                  我得到结果:1.0E-9

                  i get the result: 1.0E-9

                  我想把这个结果转换成普通的十进制符号,我该怎么做?

                  I want to convert this result into the normal decimal notation, how can i do this?

                  sprintf('%f',$ret) 不起作用,它返回 0.000000.溢出?

                  sprintf('%f',$ret) doesn't work, it returns 0.000000. Overflow?

                  推荐答案

                  sprintf('%f',$ret) 不起作用,它返回 0.000000.溢出?

                  sprintf('%f',$ret) doesn't work, it returns 0.000000. Overflow?

                  sprintf 有效,但是您在这里错过了一些要点.

                  sprintf works, however you miss some point here.

                  0.000000 没有溢出.只是 %f 修饰符的 sprintf 默认使用 6 位数字.另外请注意 %f 可以识别区域设置,%F 可能更适合.

                  0.000000 is not overflow. It's just that sprintf for the %f modifier uses 6 digits per default. Also please take care that %f is locale aware, %F is probably better suited.

                  您可能想要使用更多数字,例如假设是 4 000 000(四百万):

                  You might want to use more digits, e.g. let's say 4 000 000 (four million):

                  $ php -r "printf('%.4000000F', 1*0.000000001);"
                  
                  Notice: printf(): Requested precision of 4000000 digits was truncated to PHP maximum of 53 digits in Command line code on line 1
                  
                  Call Stack:
                      0.0001     319080   1. {main}() Command line code:0
                      0.0001     319200   2. printf() Command line code:1
                  
                  0.00000000100000000000000006228159145777985641889706869
                  

                  如本例所示,不仅有一个公共值(6 位),还有一个最大值(可能取决于 PHP 执行的计算机系统),在我的例子中,如警告所示,这里截断为 53 位.

                  As this example shows, there is not only a common value (6 digits) but also a maximum (probably depended on the computer system PHP executes on), here truncated to 53 digits in my case as the warning shows.

                  因为你的问题,我想说你想展示:

                  Because of your question I'd say you want to display:

                  0.000000001
                  

                  这是九位数字,所以你需要这样写:

                  Which are nine digits, so you need to write it that way:

                  sprintf('%.9F',$ret)
                  

                  但是,您可能想要这样做:

                  However, you might want to do this:

                  rtrim(sprintf('%.20F', $ret), '0');
                  

                  之后会从右边删除零:

                  0.000000001
                  

                  希望这有帮助.

                  这篇关于显示不带科学计数法的浮点值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:我可以依靠 PHP php.ini 精度解决方法来解决浮点问题吗 下一篇:PHP字符串浮动

                  相关文章

                    <small id='Y4A1N'></small><noframes id='Y4A1N'>

                  1. <legend id='Y4A1N'><style id='Y4A1N'><dir id='Y4A1N'><q id='Y4A1N'></q></dir></style></legend>
                      <i id='Y4A1N'><tr id='Y4A1N'><dt id='Y4A1N'><q id='Y4A1N'><span id='Y4A1N'><b id='Y4A1N'><form id='Y4A1N'><ins id='Y4A1N'></ins><ul id='Y4A1N'></ul><sub id='Y4A1N'></sub></form><legend id='Y4A1N'></legend><bdo id='Y4A1N'><pre id='Y4A1N'><center id='Y4A1N'></center></pre></bdo></b><th id='Y4A1N'></th></span></q></dt></tr></i><div id='Y4A1N'><tfoot id='Y4A1N'></tfoot><dl id='Y4A1N'><fieldset id='Y4A1N'></fieldset></dl></div>

                        <bdo id='Y4A1N'></bdo><ul id='Y4A1N'></ul>
                    1. <tfoot id='Y4A1N'></tfoot>