note 27915 modified in function.printf by jmcastagnetto
| From: | jmcastagnetto@php.net | Date: | Mon, 30 Dec 2002 12:27:18 +0000 |
| Subject: | note 27915 modified in function.printf by jmcastagnetto | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-41466@lists.php.net to get a copy of this message | ||
[Editor's note: for a simpler and more flexible solution, see number_format(), or the more
recent money_format()]
The following function can print out good format digit.
like $123,456.00
#!/usr/local/bin/php
<?php
function goodlookingnumber($f)
{
$r = "";
$r = round(fmod($f, 1000), 2);
while ($f>1000){
$f = $f/1000;
$r = round(fmod($f, 1000), 0) . ",". $r;
}
return $r;
}
$ff = 123456789.129456778;
echo $ff."\n";
echo "$".goodlookingnumber($ff) . "\n";
?>
--was--
[Editor's note: for a simpler and more flexible solution, see number_format(), or the more
recent (in CVS) money_format()]
The following function can print out good format digit.
like $123,456.00
#!/usr/local/bin/php
<?php
function goodlookingnumber($f)
{
$r = "";
$r = round(fmod($f, 1000), 2);
while ($f>1000){
$f = $f/1000;
$r = round(fmod($f, 1000), 0) . ",". $r;
}
return $r;
}
$ff = 123456789.129456778;
echo $ff."\n";
echo "$".goodlookingnumber($ff) . "\n";
?>
http://www.php.net/manual/en/function.printf.php