Snippet Name: Format money as millions, billions, etc
Description: This function formats a money amount into an abbreviated form. It takes a number like "1,246,743" and formats it as "1.25 million", (or billion, trillion, etc.)
Also see: » Format money as millions, billions, et...
» BR2NL Function: Opposite of NL2BR
» Neatly trim a string to a set number o...
» Convert UK Dates To mySQL Format Dates
» Output mySQL data in columns
» SQL*Plus Display commands
» Create string by formatting an amount ...
» Date Functions: ROUND
» Display and release DBMS_LOCK locks
» Display locks and latches
» Display database SGA statistics
» Extract and Display all links on a web...
» Currency display formatting function
» Display stock quotes from a CSV file
» Display html source with line numbers
» Rounded random numbers
» Date Functions: Round (date)
» Number Functions: Round to n
» Number Functions: Round to integer
Comment: (none)
Language: PHP
Highlight Mode: PHP
Last Modified: June 27th, 2010
|
FUNCTION format_cash($cash) {
// strip any commas
$cash = (0 + STR_REPLACE(',', '', $cash));
// make sure it's a number...
IF(!IS_NUMERIC($cash)){ RETURN FALSE;}
// filter and format it
IF($cash>1000000000000){
RETURN ROUND(($cash/1000000000000),2).' trillion';
}ELSEIF($cash>1000000000){
RETURN ROUND(($cash/1000000000),2).' billion';
}ELSEIF($cash>1000000){
RETURN ROUND(($cash/1000000),2).' million';
}ELSEIF($cash>1000){
RETURN ROUND(($cash/1000),2).' thousand';
}
RETURN NUMBER_FORMAT($cash);
} |