[b]Commify:[/b]
This function inserts a comma separator into every 3 digits.
[i]For Example:[/i]
commify (100000);
Output will be: 100,000
function commify ($str) {
$n = strlen($str);
if ($n <= 3) { $return=$str; }
else {
$pre=substr($str,0,$n-3);
$post=substr($str,$n-3,3);
$pre=commify($pre);
$return="$pre,$post";
}
return($return);
}
[b]Dollarfy:[/b]
Does the following things to a floating point number:
1. This function inserts a comma separator into every 3 digits.
For example: 100000.1252 will be 100,000.1252.
2. Round to the decimal number to the next significant figure.
For example: 100,000.1252 will be 100,000.13
3. Add a dollar sign to the number.
For example: 100,000.13 will be $100,000.13
function dollarfy ($num,$dec) {
$format="%.$dec" . "f";
$number=sprintf($format,$num);
$str=strtok($number,".");
$dc=strtok(".");
$str=commify($str);
$return="\$".$str;
if ($dec!=0) { $return = $return . "." . $dc; }
return($return);
}