1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
function num2metric($num, $precision = 0) { $unitList = [ 'P' => 15, 'T' => 12, 'G' => 9, 'M' => 6, 'W' => 4, 'K' => 3, ];
$num = (int) $num;
foreach($unitList as $name => $pow) { $size = pow(10, $pow);
if($num >= $size) { return bcdiv($num, $size, $precision) . $name; } }
return $num; }
num2metric(1000) num2metric('10000') num2metric('A')
|
度量单位列表
Text |
Symbol |
Power |
yotta |
Y |
1024 |
zetta |
Z |
1021 |
exa |
E |
1018 |
peta |
P |
1015 |
tera |
T |
1012 |
giga |
G |
109 |
mega |
M |
106 |
kilo |
K |
103 |
W 并非国际度量单位,是由中文 万 拼音转换而成的
参考
Metric prefix