Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine currency symbol position for a culture

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?

like image 821
Darryl Avatar asked Jul 03 '13 23:07

Darryl


1 Answers

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 $ 
like image 67
keyboardP Avatar answered Sep 28 '22 20:09

keyboardP