印度货币的PHP货币格式?

问题描述:

例如$num='7,57,800';印度货币的PHP货币格式?

如何显示$number的值为7.57拉赫?

+0

串money_format(字符串$格式,浮$号)? – PurplePilot 2011-12-18 08:19:34

+1

澄清:你是否试图将'7,57,800'转换为'7.57 Lakhs'?或试图将'757800'转换为'7,57800'? – 2011-12-18 08:59:46

这里的功能:

function formatInIndianStyle($num){ 
    $pos = strpos((string)$num, "."); 
    if ($pos === false) { 
     $decimalpart="00"; 
    } 
    if (!($pos === false)) { 
     $decimalpart= substr($num, $pos+1, 2); $num = substr($num,0,$pos); 
    } 

    if(strlen($num)>3 & strlen($num) <= 12){ 
     $last3digits = substr($num, -3); 
     $numexceptlastdigits = substr($num, 0, -3); 
     $formatted = makeComma($numexceptlastdigits); 
     $stringtoreturn = $formatted.",".$last3digits.".".$decimalpart ; 
    }elseif(strlen($num)<=3){ 
     $stringtoreturn = $num.".".$decimalpart ; 
    }elseif(strlen($num)>12){ 
     $stringtoreturn = number_format($num, 2); 
    } 

    if(substr($stringtoreturn,0,2)=="-,"){ 
     $stringtoreturn = "-".substr($stringtoreturn,2); 
    } 

    return $stringtoreturn; 
} 

function makeComma($input){ 
    if(strlen($input)<=2) 
    { return $input; } 
    $length=substr($input,0,strlen($input)-2); 
    $formatted_input = makeComma($length).",".substr($input,-2); 
    return $formatted_input; 
} 

入住这plugin- http://archive.plugins.jquery.com/project/numberformatter

这里是你如何使用这个插件的例子。

$("#salary").blur(function(){ 
$(this).parseNumber({format:"#,###.00", locale:"us"}); 
$(this).formatNumber({format:"#,###.00", locale:"us"}); 
}); 

只要改变区域..

更多例子和信息visit- http://code.google.com/p/jquery-numberformatter/

我的例子来源:http://code.google.com/p/jquery-numberformatter/

希望这有助于:)

这里是另一个解决方案仅供参考:

<?php 
# Output easy-to-read numbers 
# by james at bandit.co.nz 
function bd_nice_number($n) { 
    // first strip any formatting; 
    $n = (0+str_replace(",","",$n)); 

    // is this a number? 
    if(!is_numeric($n)) return false; 

    // now filter it; 
    if($n>1000000000000) return round(($n/1000000000000),1).' trillion'; 
    else if($n>1000000000) return round(($n/1000000000),1).' billion'; 
    else if($n>1000000) return round(($n/1000000),1).' million'; 
    else if($n>1000) return round(($n/1000),1).' thousand'; 

    return number_format($n); 
} 
?> 

<?php //Credits are going to: @Niet-the-Dark-Absol 

    function indian_number_format($num){ 
     $num=explode('.',$num); 
     $dec=(count($num)==2)?'.'.$num[1]:'.00'; 
     $num = (string)$num[0]; 
     if(strlen($num) < 4) return $num; 
     $tail = substr($num,-3); 
     $head = substr($num,0,-3); 
     $head = preg_replace("/\B(?=(?:\d{2})+(?!\d))/",",",$head); 
     return $head.",".$tail.$dec; 
    } 
?> 

问题:从PHP手册*.com/questions/10042485