Вот версия log()
, если вы все еще заинтересованы:
function wordify($val, $decimalPlaces = 1) {
if ($val < 1000 && $val > -1000)
return $val;
$a = array( 0 => "", 1 => "K", 2 => "Mil", 3 => "Bil", 4 => "Tril", 5 => "Quad" );
$log1000 = log(abs($val), 1000);
$suffix = $a[$log1000];
return number_format($val / pow(1000, floor($log1000)), $decimalPlaces, '.', '') . " $suffix";
}
$tests = array(-1001, -970, 0, 1, 929, 1637, 17000, 123456, 1000000, 1000000000, 1234567890123);
foreach ($tests as $num) {
echo wordify($num)."<br>";
}