Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting fatal error in money_format function

Tags:

php

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() 
like image 691
Parthi04 Avatar asked May 23 '12 07:05

Parthi04


2 Answers

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).

like image 95
kapa Avatar answered Oct 06 '22 05:10

kapa


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

$price = number_format($price, 2); echo “$”.$price;
like image 21
ZUMRAN Avatar answered Oct 06 '22 05:10

ZUMRAN