note 102068 added to function.money-format
| From: | sammy dot diakite at gmail dot com | Date: | Wed, 26 Jan 2011 01:32:07 +0000 |
| Subject: | note 102068 added to function.money-format | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-176313@lists.php.net to get a copy of this message | ||
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
----
Server IP: 69.147.83.197
Probable Submitter: 41.203.197.57
----
Manual Page -- http://www.php.net/manual/en/function.money-format.php
Edit -- https://master.php.net/note/edit/102068
Del: integrated -- https://master.php.net/note/delete/102068/integrated
Del: useless -- https://master.php.net/note/delete/102068/useless
Del: bad code -- https://master.php.net/note/delete/102068/bad+code
Del: spam -- https://master.php.net/note/delete/102068/spam
Del: non-english -- https://master.php.net/note/delete/102068/non-english
Del: in docs -- https://master.php.net/note/delete/102068/in+docs
Del: other reasons-- https://master.php.net/note/delete/102068
Reject -- https://master.php.net/note/reject/102068
Search -- https://master.php.net/manage/user-notes.php