Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要一个 PHP 函数来格式化 Facebook“喜欢”之类的数字。
例子:
12345 = 12,3 千
123456 = 123 千
1234567 = 1,23 M
谢谢!!
写一个函数来做这个!?
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"; }