【问题标题】:Format numbers like Facebook "likes" - PHP [closed]像Facebook“喜欢”这样的格式数字 - PHP [关闭]
【发布时间】:2013-03-04 14:55:22
【问题描述】:

我需要一个 PHP 函数来格式化 Facebook“喜欢”之类的数字。

例子:

12345 = 12,3 K

123456 = 123 K

1234567 = 1,23 百万

谢谢!!

【问题讨论】:

标签: php numbers format


【解决方案1】:

写一个函数来做这个!?

function format_num($n) {
    $s = array("K", "M", "G", "T");
    $out = "";
    while ($n >= 1000 && count($s) > 0) {
        $n = $n / 1000.0;
        $out = array_shift($s);
    }
    return round($n, max(0, 3 - strlen((int)$n))) ." $out";
}

【讨论】:

  • 好的!它帮助到我!!非常感谢!!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-03
  • 1970-01-01
  • 1970-01-01
  • 2018-02-26
  • 1970-01-01
相关资源
最近更新 更多