I am trying to determine whether the currency symbol for a given culture should appear at the beginning or end of the value. I have not been able to find this bit of information in the .Net CultureInfo, so I thought I'd try a hack:
var cultures = new[] {"en-US", "ar-SA", "as-IN", "tr-TR"};
foreach ( var culture in cultures ) {
var cultureInfo = CultureInfo.CreateSpecificCulture( culture );
var currencyValue = 1.234.ToString( "C", cultureInfo );
var rtl = cultureInfo.TextInfo.IsRightToLeft;
var symbolAtBeginning = currencyValue.StartsWith( cultureInfo.NumberFormat.CurrencySymbol, false, cultureInfo );
}
Alas, this method works only sometimes; in the example above, it works for "en-US" but not the rest of the cultures. At first I thought it was because some cultures read text right-to-left, and the "start" would be the right side, but that explanation did not prove out.
Does anyone see the flaw in my code, or preferably, have a better method for determining the currency symbol position?
You can use the NumberFormatInfo class to determine that information. You can read the CurrencyPositive property for positive values and it will return an int
repesenting the position. From MSDN:
0 $n
1 n$
2 $ n
3 n $
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With