How to display Currency in Indian Numbering Format in PHP

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

    $amount=-3000000000111.11;
    $amount<0?(($sign='-').($amount*=-1)):$sign=''; //Extracting sign from given amount
    $pos=strpos($amount, '.'); //Identifying the decimal point position
    $amt=  substr($amount, $pos-3); // Extracting last 3 digits of integer part along with fractional part
    $amount=  substr($amount,0, $pos-3); //removing the extracted part from amount
    for(;strlen($amount);$amount=substr($amount,0,-2)) // Now loop through each 2 digits of remaining integer part
        $amt=substr ($amount,-2).','.$amt; //forming Indian Currency format by appending (,) for each 2 digits
    echo $sign.$amt; //Appending sign
    

提交回复
热议问题