PDA

View Full Version : format currency


NancyJ
02-27-2006, 12:57 PM
In asp there is a format_currency() function, now I assumed money_format in php would be the same but I just cant get it to display the £ sign at all.
It formats the number with 2 decimal places but no £ sign.

donmarvin
02-27-2006, 01:43 PM
on phpfreaks.com, the following code was contributed by a user at http://us2.php.net/manual/en/function.money-format.php:

stefan at ioc dot nl -- 15-Jan-2004 09:31 says:
To display EUR or the euro-sign, try this:

<?php
setlocale(LC_ALL, 'nl_NL@euro');
echo money_format('%i', 10000);
echo "<br>";
echo htmlentities(money_format('%.2n', 10000),ENT_QUOTES,'ISO-8859-15');
?>

NancyJ
02-27-2006, 01:59 PM
Yeah I saw that - it just prints out 10000.00 both times

donmarvin
02-27-2006, 02:00 PM
It prints out fine for me: http://websitesbydonna.com/test.php

NancyJ
02-27-2006, 02:09 PM
I've pasted in directly from the php manual and no £ or $ or euro symbol. What version of php are you using?

donmarvin
02-27-2006, 02:19 PM
PHP Version 4.4.1

donmarvin
02-27-2006, 02:29 PM
I've added my complete php info to the test page:

http://websitesbydonna.com/testphp.php

NancyJ
02-27-2006, 02:59 PM
We're running php 5

fci
02-27-2006, 03:39 PM
what does this output:
<pre><?php
if (false !== setlocale(LC_ALL, 'nl_NL.UTF-8@euro')) {
$locale_info = localeconv();
print_r($locale_info);
}
?></pre>

or
<pre><?php echo `locale -a`; ?></pre>

NancyJ
02-27-2006, 03:50 PM
The first one prints out nothing (well <pre></pre>) and the second one,
C
POSIX

donmarvin
02-27-2006, 04:02 PM
I tried running it on my local web server and it didn't work!

I get this error message: Call to undefined function: money_format()

My local webserver is running PHP Version 4.3.10

donmarvin
02-27-2006, 04:05 PM
Oh, this is why it's not running on my local webserver:

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


Is your website running on a Windows server?

NancyJ
02-27-2006, 04:07 PM
no, we're running on debian.

The function runs, it adds the decimals but it doesnt add the symbol.

fci
02-27-2006, 04:10 PM
The first one prints out nothing (well <pre></pre>) and the second one,
C
POSIX

looks like your server doesn't seem to support all the locales. on my local server I get 319 different locales.. I'd suggest talking to your webhost/sysadmin to get them added. or, roll your own function.

NancyJ
02-27-2006, 04:17 PM
I'd suggest talking to your webhost/sysadmin to get them added.

That would be me ;)

donmarvin
02-27-2006, 04:21 PM
ROFL!

Try godaddy.com. For $3.95/month you save yourself a lot of time and headaches.

fci
02-27-2006, 04:26 PM
That would be me ;)

let us know how it goes then

NancyJ
02-27-2006, 04:36 PM
All sorted now. Its this new server, its all shiny and new and missing stuff lol.

For anyone else running a debian server ;)
apt-get install locales