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.
Facebookの「いいね」のような数値をフォーマットするには、PHPの関数が必要です。
例:
12345 = 12,3K
123456 = 123K
1234567 = 1,23 メートル
ありがとうございました!!
これを行う関数を書きます!?
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"; }