Forum Moderators: phranque

Message Too Old, No Replies

i18n and l10n and formatting currencies. ?

         

httpwebwitch

8:04 pm on Sep 1, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The currency formatting class I have applies formatting to a number based on the currency it is. For example:

currency_format(2100000.43,"USD")
is formatted like:
$2,100,000.43

currency_format(2100000.43,"CAD")
C$2,100,000.43

currency_format(2100000.43,"EUR")
2.100.000,43 €

A little online research tells me that these formats aren't always done that way.
In particular, the Euro is used in countries with a variety of languages, and the number formatting preference in those languages is different.

for example:
Swiss:
2'100'000,43 €

German:
2.100.000,43 €

French:
2 100 000,43 €

I don't even know of those are correct.
But it seems apparent that it's not just the currency that matters, it's the currency and the locale, together.

I'm pretty sure someone in Germany - even if they're expressing USD$, would write
2.100.000,43 $USD
Whereas someone in Canada will write:
USD$2,100,000.43

Or does the currency go before the number? What dictates that?

Could you please reply and state, for the record, how currency is expressed in your country?

PHP has a built-in money_format() function, but I don't trust that it's doing the right thing. The manpage comments are full of criticisms and hacks. I'll build my own thanks


Here's mine:

Canadian English

positive:
$12,345.67
or
C$12,345.67

negative:
-$12,345.67

Canadian French

positive:
12.345,67 $
or
12.345,67 C$

negative:
-12.345,67 $

coopster

12:30 pm on Sep 8, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yes, you are correct in the locale coming into play. However, it may not be PHP but your underlying OS. It's been awhile since I pulled the PHP source but if I remember correctly it uses
strfmon
and your LC_MONETARY category of the locale but I may be mixing up my languages :P

Research those two values though and you should be able to pull a little more information that might lead you in the proper direction.