【问题标题】:PHP Number FormattingPHP 数字格式
【发布时间】:2014-05-01 11:07:57
【问题描述】:

我整个上午都在尝试,但是我如何将这个号码 1304583496 看起来像这样

13.04583496

这个数字也是如此

4566042234.56604223

右边总是有 8 个数字。

【问题讨论】:

  • 如果右边总是有 8 个数字,你不能只除以 100 000 000 吗?
  • echo sprintf('%.8f',$n/100000000);

标签: php formatting numbers


【解决方案1】:

除以 100000000,或使用“pow”函数:

$number / pow(10, 8);

【讨论】:

    【解决方案2】:

    你也可以在除法之后使用官方的number_format方法来保持你的结尾零并以一种很好的方式显示你的数字。

    <?php
    $num = 1304583496; //the number
    echo number_format($num/100000000,8,"."," "); //number of decimals = 8, comma seperator is . and thousands seperator is a space here
    ?>
    

    有关此功能的更多信息:http://www.w3schools.com/php/func_string_number_format.asp

    【讨论】:

      猜你喜欢
      • 2011-09-12
      • 2016-10-29
      • 2016-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多