note 84634 added to function.money-format

From: Date: Wed, 23 Jul 2008 03:24:55 +0000
Subject: note 84634 added to function.money-format
Groups: php.notes 
Request: Send a blank email to php-notes+get-142581@lists.php.net to get a copy of this message
Consider formatting currency for some South Asian countries that use ##,##,###.## money format. The following code generates something like Rs. 4,54,234.00 and so on. function convertcash($num, $currency){ if(strlen($num)>3){ $lastthree = substr($num, strlen($num)-3, strlen($num)); $restunits = substr($num, 0, strlen($num)-3); // extracts the last three digits $restunits = (strlen($restunits)%2 == 1)?"0".$restunits:$restunits; // explodes the remaining digits in 2's formats, adds a zero in the beginning to maintain the 2's grouping. $expunit = str_split($restunits, 2); for($i=0; $i<sizeof($expunit); $i++){ $explrestunits .= (int)$expunit[$i].","; // creates each of the 2's group and adds a comma to the end } $thecash = $explrestunits.$lastthree; } else { $thecash = $convertnum; } return $currency.$thecash.".00"; // writes the final format where $currency is the currency symbol. } now call the function as convertcash($row['price'], 'Rs '); // that's the price from the database I called using an Indian Rupees prefix where the price has to be a plain number format, say something like 454234. ---- Server IP: 69.147.83.197 Probable Submitter: 69.88.8.8 (proxied: 202.51.84.39) ---- Manual Page -- http://www.php.net/manual/en/function.money-format.php Edit -- https://master.php.net/note/edit/84634 Del: integrated -- https://master.php.net/note/delete/84634/integrated Del: useless -- https://master.php.net/note/delete/84634/useless Del: bad code -- https://master.php.net/note/delete/84634/bad+code Del: spam -- https://master.php.net/note/delete/84634/spam Del: non-english -- https://master.php.net/note/delete/84634/non-english Del: in docs -- https://master.php.net/note/delete/84634/in+docs Del: other reasons-- https://master.php.net/note/delete/84634 Reject -- https://master.php.net/note/reject/84634 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#142581) next »