How to display Currency in Indian Numbering Format in PHP

后端 未结 22 2141
一整个雨季
一整个雨季 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:53

    So if I'm reading that right, the Indian Numbering System separates the thousands, then every power of a hundred past that? Hmm...

    Perhaps something like this?

    function indian_number_format($num) {
        $num = "".$num;
        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;
    }
    

提交回复
热议问题