10

Why does this error occurs?

code:

setlocale(LC_MONETARY, "en_US");
$pricetotal = money_format("%10.2n", $pricetotal);

Server details.

Apache Version : 2.2.21  
PHP Version : 5.3.8 

I'm getting the following Error

Fatal error: Call to undefined function money_format() 
hakre
  • 193,403
  • 52
  • 435
  • 836
Parthi04
  • 1,121
  • 4
  • 21
  • 39
  • do you have any other code? that should work; only reason I could suggest at this junction is that you're inside a namespace... – Ian Wood May 23 '12 at 07:56
  • 3
    possible duplicate of [How we can use money_format() function in php on windows platform.?](http://stackoverflow.com/questions/6369887/how-we-can-use-money-format-function-in-php-on-windows-platform) – deceze May 23 '12 at 08:02
  • Here is the Solutions.. It Worked .http://www.php.net/manual/en/function.money-format.php#89060 – Parthi04 May 23 '12 at 08:06

3 Answers3

15

From the manual:

The function money_format() is only defined if the system has strfmon capabilities. For example, Windows does not, so money_format() is undefined in Windows.

money_format() is basically a wrapper around the C library function strfmon() as the manual states.

If you check the comments, there is an implementation by Rafael M. Salvioni. Worth a try. You can check if it's already defined using function_exists().

Answers to this StackOverflow question give further (and possibly better) alternatives (thx danielson317).

Community
  • 1
  • 1
kapa
  • 77,694
  • 21
  • 158
  • 175
  • I just add function there is an implementation by Rafael M. Salvioni to my web then it's works. +1 for the links – bungdito Jul 17 '13 at 04:28
  • That function doesn't work for me. I get Severity: Warning Message: implode(): Invalid arguments passed – CMCDragonkai Jan 07 '14 at 07:29
  • 1
    the intl module mentioned in http://stackoverflow.com/questions/6369887/how-we-can-use-money-format-function-in-php-on-windows-platform is a much better solution. Still +1 for being a valid answer. – danielson317 Apr 29 '15 at 16:44
  • @danielson317 Thanks, added the link to my answer. – kapa Apr 29 '15 at 19:11
4

For those that money_format doesn't work, you can use:

$price = number_format($price, 2); echo “$”.$price;
NemoXP
  • 896
  • 6
  • 5
ZUMRAN
  • 41
  • 1
1

Perhaps this?

Note:

The function money_format() is only defined if the system has strfmon capabilities. For example, Windows does not, so money_format() is undefined in Windows.

http://php.net/money_format

Community
  • 1
  • 1
deceze
  • 510,633
  • 85
  • 743
  • 889