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.
我想要这样的数字格式:
1000 = 1k 10500 = 10.5k 1843 = 1.8k 17434 = 17.4k
但我不知道该怎么做。语言是PHP
谢谢您的帮助!
尝试这个:
$num = 14600; if($num >= 1000) { echo round(($num/1000),1) . 'k'; }
这将满足您的需要。
<?php $num = 10234; echo round($num/1000*100)/100.'k'; ?>
这应该适用于任何数字。
$num = 1000; echo round($num / 1000) . "k";