Alternative to money_format() Function in PHP on Windows Platform

前端 未结 13 1917
天命终不由人
天命终不由人 2020-12-01 09:02

I am using the money_format() function in PHP, which gives the following error:

Fatal error: Call to undefined function money_format()
         


        
13条回答
  •  -上瘾入骨i
    2020-12-01 09:50

    If you have the Intl extension, you can use

    • NumberFormatter::formatCurrency — Format a currency value according to the formatter rules.

    Example from Manual

    $fmt = new NumberFormatter( 'de_DE', NumberFormatter::CURRENCY );
    echo $fmt->formatCurrency(1234567.891234567890000, "EUR")."\n";
    echo $fmt->formatCurrency(1234567.891234567890000, "RUR")."\n";
    $fmt = new NumberFormatter( 'ru_RU', NumberFormatter::CURRENCY );
    echo $fmt->formatCurrency(1234567.891234567890000, "EUR")."\n";
    echo $fmt->formatCurrency(1234567.891234567890000, "RUR")."\n";
    

    Output

    1.234.567,89 €
    1.234.567,89 RUR
    1 234 567,89€
    1 234 567,89р.
    

    Also see my answer on how to parse that formatted money string back into a float:

    • PHP: unformat money

提交回复
热议问题