This should be an easy problem but...
I need to format a currency for display (string) in C#
The currency in question will have its own rules such as the symbol to use and if that symbol should come before the value (e.g. $ 10) or after (e.g. 10 ? which is Vietnamese Dong).
But how the numbers are formatted depends upon the users local, not the currency.
E.g.
1.234,56 ? should be displayed to a user in Vietnam but
1,234.56 ? should be displayed to a user in the US
(formatted as code so easy to see difference between , and.)
So code like
Double vietnamTotal = 1234.56;
return vietnamTotal.ToString("c");
Won't work as it will use the users (or more accuratly CultureInfo.CurrentCulture) locale for format and currency so you would get things like $1,123.56 - right use of , and . but wrong symbol.
Double vietnamTotal = 1234.56;
CultureInfo ci = new CultureInfo(1066); // Vietnam
return vietnameTotal.ToString("c",ci));
Would give 1.234,56 ? - Right symbol, wrong use of , and . for current user.
This post gives more detail on the right thing to do, but not how to do it.
What obvious method hidden in the framework am I missing?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…