note 102068 deleted from function.money-format by danbrown

From: Date: Wed, 26 Jan 2011 01:44:28 +0000
Subject: note 102068 deleted from function.money-format by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-176314@lists.php.net to get a copy of this message
Note Submitter: sammy dot diakite at gmail dot com ---- function msi_money($string_money, $separator=0) { /* msi_money(100, " ") will output 100 * msi_money(1000, " ") will output 1 000 * msi_money(1000, ",") will output 1,000 * msi_money(1000, ".") will output 1.000 * **/ $count = strlen($string_money); if($separator != 0)$spt = $separator; else $spt = " "; if ($count < 4) return $string_money; else if (($count > 3) && ($count < 7)) return substr($string_money, -$count, -3).$spt.substr($string_money, -3); else if (($count > 6) && ($count < 10)) return substr($string_money, -$count, -6).$spt.substr($string_money, -6, -3).$spt.substr($string_money, -3); else if (($count > 9) && ($count < 13)) return substr($string_money, -$count, -9).$spt.substr($string_money, -9, -6).$spt.substr($string_money, -6, -3).$spt.substr($string_money, -3); else if (($count > 12) && ($count < 16)) return substr($string_money, -$count, -12).$spt.substr($string_money, -12, -9).$spt.substr($string_money, -9, -6).$spt.substr($string_money, -6, -3).$spt.substr($string_money, -3); } print msi_money(100); // will output 100 print msi_money(1000,"."); // will output 1.000 print msi_money(1000000, ","); // will output 1,000,000 print msi_money(1000000000, " "); // will output 1 000 000 000 print msi_money(1000000000); // will output 1 000 000 000 // the default value is SPACE

« previous php.notes (#176314) next »