views:

67

answers:

1

Many languages, such as .NET languages and Java come with a currency formatting facility built-in. What they do is format a number using a culture-specific number format and add the culture's currency symbol.

The problem here is that the number format is strongly coupled to the currency symbol. In practice the number format should be the correct one for the language of the surrounding text, while the currency symbol should be for the currency being talked about. For example, you wouldn't use American thousand separators when talking about US Dollars in a document that's in German.

Can you think of a practical use for this kind of currency formatting functions, or do they exist just to impress money-oriented management people?

+1  A: 

At least in .NET the number format is tied to a culture, not the symbol. The default currency symbol is the primary one associated with that culture. The symbol can be overridden as required.

Like your example, if I'm embedding a currency value in a string then I use the string's culture for the format, but override the currency symbol appropriately. The rest of the formatting is left as-is.

On the other hand if I'm doing a report all of the values are formatted using the same culture. I normally use the ISO 3-character codes instead of currency symbols in this case, especially if more than 2 currencies are involved, to avoid font issues.

Ryan's answer to another question describes the what and how Best Practices for currency formatting in C#.

devstuff
Changing the currency symbol is a good point, although it requires an awful lot of code for something that IMHO should be a part of the format parameters. It's also easy to run into problems with currency symbols displayed on the wrong size ($50 vs. 50 kr), not to mention that some currencies actually change order depending on the locale (€50 vs. 50€)
Matti Virkkunen
I ended up writing an extension method on `decimal` to handle all the drudge work, somewhat similar to Jon Skeet's example here: http://stackoverflow.com/questions/1071273/currency-formatting/1071302#1071302
devstuff