I'm using .ToString("C")
method to show decimal number in currency format. But result looks lke "US$5,365.20" instead of "$5,365.20". I've tried to use .ToString("C", new CultureInfo("en-US"))
, results the same. But when I've tried to use another culture (en-GB, for example) then everything was ok (£1,234.56).
So, why "US" is appeared before "$" symbol? And how can I remove it?
UPD I'm sorry. Just checked it again, and i see, that with new CultureInfo("en-US"))
all works perfectly, i looked on another label :) But now i see(thanks to @Mike McCaughan), that current currency symbol is "US$". Current culture name is 'en-US'.
Remove 'US' before '$' in currency displaying
1.8k views Asked by Eugen Tatuev At
3
There are 3 answers
3
On
Testing what Mike McCaughan
has provided I think that it will remove the US
but it will also add $$
to the existing Currency. I have tested this and this will work, but I think that there are some better ways of doing this but this will yield the following
Remove the US
initially would solve this in one line..
var currency = "US$5,365.20".Replace("US", string.Empty);
or Alternative
Taking B.K
suggestion you can take this even one more level from 3 lines to 2 lines
var currency = 5365.20M;
var finalCurrency = currency.ToString("C", new CultureInfo("en-US")).Replace("US", string.Empty);
0
On
You can change the currency symbol for that specific culture's shallow clone:
var d = 2353.23M;
var currencyFormat = (NumberFormatInfo)CultureInfo.GetCultureInfo("en-US").NumberFormat.Clone();
currencyFormat.CurrencySymbol = "$"; // Change to something like %^# to test it
var currency = d.ToString("C", currencyFormat);
"US" appears before "$" because someone customized the currency symbol using the Region applet in Control Panel. To get the default currency symbol, use
CultureInfo.GetCultureInfo
instead of the constructor:The MSDN Library documentation explains the difference. For the constructor:
And for GetCultureInfo:
UPDATE: If
.ToString("C", new CultureInfo("en-US"))
works but.ToString("C")
doesn't, then the problem could be that some other code assigned your thread a custom CultureInfo with "US$" as the currency symbol.