Is there any PHP function to convert number to currency with thousands separators?

后端 未结 2 2001
野的像风
野的像风 2021-01-28 01:28

Is there any PHP function to convert an integer to Lakh and Crore?

900800 -> 9,00,800
500800 -> 5,00,800
相关标签:
2条回答
  • 2021-01-28 01:39

    For most locales, use number_format: http://php.net/manual/en/function.number-format.php

    For India (Lakh & Crore) use formatInIndianStyle provided in this comment: http://php.net/manual/en/function.number-format.php#40558

    0 讨论(0)
  • 2021-01-28 01:58

    As you have added Yii in your question tags, you can do this in Yii's way like below:

    Yii::app()->language='en_IN';
    // Output: Lakh 9,00,800
    echo Yii::app()->numberFormatter->formatCurrency('900800', 'Lakh');
    
    // Output: ₹ 5,00,800
    echo Yii::app()->numberFormatter->formatCurrency('500800', 'INR');
    
    0 讨论(0)
提交回复
热议问题