tags:

views:

141

answers:

1

I have created a Money class to save money values in different currencies. The class uses 3 letter ISO symbols to store currency types:

public class Money
{
    public decimal Amount { get; set; }
    public string Currency { get; set; }
}

Is there a way in C# to use this information, say 100.00 USD, and format it as "$100.00"? Only way I know of requires CultureInfo like this:

Amount.ToString("C", CultureInfo.CreateSpecificCulture("en-US"));

However this does not work with my Money class. Is there another solution? I am open to changing my Money class.

I have searched this site for similar questions (such as this), but couldn't find one that answers the above question.

+2  A: 

That's a non-trivial localization issue you have there. Look at these examples from MSDN:

123.456 ("C", en-US) -> $123.46
123.456 ("C", fr-FR) -> 123,46 €
123.456 ("C", ja-JP) -> ¥123

How would you display USD 123.456 to someone in France? $123.46 or 123,46 $?

I'd probably stick with displaying it using the 3 letter ISO symbol, although the position of this symbol seems to vary in different countries as well. From usage guidelines for the EUR symbol:

In English texts, the ISO code ‘EUR’ is followed by a fixed space and the amount:

a sum of EUR 30

NB: The same rule applies in Irish, Latvian and Maltese. In all other official EU languages the order is reversed; the amount is followed by a fixed space and the ISO code ‘EUR’ (or the euro sign in graphics):

une somme de 30 EUR
dtb
Hmmm..., I understand what you are saying. I wish there was at least a way to format all currencies for a given local. For example, if running in en-US locale, USD would be shown as $100.00 and Yen would be shown as ¥123.
Naresh