How to display Currency in Indian Numbering Format in PHP

后端 未结 22 2131
一整个雨季
一整个雨季 2020-12-01 06:14

I have a question about formatting the Rupee currency (Indian Rupee - INR).

For example, numbers here are represented as:

1
10
100
1,000
10,000
1,00,00         


        
22条回答
  •  悲&欢浪女
    2020-12-01 06:49

    Check this code, it works 100% for Indian Rupees format with decimal format. You can use numbers like :

    123456.789 123.456 123.4 123 and 1,2,3,4,5,6,7,8,9,.222

    function moneyFormatIndia($num){
    
    $explrestunits = "" ;
    $num = preg_replace('/,+/', '', $num);
    $words = explode(".", $num);
    $des = "00";
    if(count($words)<=2){
        $num=$words[0];
        if(count($words)>=2){$des=$words[1];}
        if(strlen($des)<2){$des="$des";}else{$des=substr($des,0,2);}
    }
    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

提交回复
热议问题