public static string FormatWithISOCurrencySymbol(Decimal amount, string ISOCurrencySymbol = null)
        {
            NumberFormatInfo numberFormat = null;

            if (ISOCurrencySymbol != null)
            {
                numberFormat = (from c in CultureInfo.GetCultures(CultureTypes.SpecificCultures)
                                let r = new RegionInfo(c.LCID)
                                        where r != null &&
                                        r.ISOCurrencySymbol.ToUpper() == ISOCurrencySymbol.ToUpper()
                                        select c).First().NumberFormat;
            }
            else
            {
                numberFormat = CultureInfo.CurrentCulture.NumberFormat;
                var specificCulture = CultureInfo.CreateSpecificCulture(CultureInfo.CurrentCulture.Name);
                ISOCurrencySymbol = new RegionInfo(specificCulture.LCID).ISOCurrencySymbol;
            }

            var numberFormatInfo = (NumberFormatInfo)numberFormat.Clone();

            numberFormatInfo.CurrencySymbol = ISOCurrencySymbol.ToUpper();

            // Add spaces between the figure and the currency
            //https://docs.microsoft.com/en-us/dotnet/api/system.globalization.numberformatinfo.currencypositivepattern?redirectedfrom=MSDN&view=netframework-4.7.2#System_Globalization_NumberFormatInfo_CurrencyPositivePattern
            //n $
            numberFormatInfo.CurrencyPositivePattern = 3;
            //https://docs.microsoft.com/en-us/dotnet/api/system.globalization.numberformatinfo.currencynegativepattern?redirectedfrom=MSDN&view=netframework-4.7.2#System_Globalization_NumberFormatInfo_CurrencyNegativePattern
            //-n $
            numberFormatInfo.CurrencyNegativePattern = 8;

            return(amount.ToString("C", numberFormatInfo));
        }
Example #2
0
 public override int GetHashCode()
 {
     return(ISOCurrencySymbol != null ? ISOCurrencySymbol.GetHashCode() : 0);
 }