note 93893 deleted from function.number-format by levim
| From: | levim@php.net | Date: | Sun, 23 Mar 2014 14:12:13 +0000 |
| Subject: | note 93893 deleted from function.number-format by levim | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-199018@lists.php.net to get a copy of this message | ||
Note Submitter: Horvath, Sandor [HU]
----
Because I had a lot of problems with number_format, here is a working, simple and small replacement:
<?php
function FormatNumber($number, $decimals = 0, $thousand_separator = ' ',
$decimal_point = '.')
{
$tmp1 = round((float) $number, $decimals);
while (($tmp2 = preg_replace('/(\d+)(\d\d\d)/', '\1 \2', $tmp1)) != $tmp1)
$tmp1 = $tmp2;
return strtr($tmp1, array(' ' => $thousand_separator, '.' =>
$decimal_point));
}
echo FormatNumber(-913578.1415, 2, '.', ',') . "\n";
?>