У меня есть фрагмент кода, который форматирует число в цену INR (1,00 рупий/-, 10 00000,00 рупий/- и т. д.): [code]function price_format($num,$type = 1){ $num_full = number_format($num,2); if (strpos($num, '.') !== false) { $num = substr($num_full, 0, strpos($num_full, ".")); }
if($type == 1){ // '₹10,00,000.00/-' $explrestunits = "" ; 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