note 27915 deleted from function.printf by tomsommer
| From: | tomsommer@php.net | Date: | Sat, 10 Jul 2004 00:04:26 +0000 |
| Subject: | note 27915 deleted from function.printf by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-72952@lists.php.net to get a copy of this message | ||
Note Submitter: gwang@structure-tech.com
----
[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";
?>