Beispiel #1
0
        /// <summary>
        /// Format the currency value into it's localized currency pattern
        /// </summary>
        /// <param name="sCurrencyValue">The currency value</param>
        /// <param name="sTargetCurrency">The target currency to base on</param>
        /// <returns>The formatted currency string</returns>
        public virtual string FormatCurrencyWithoutCurrencyCode(string sCurrencyValue, string sTargetCurrency)
        {
            InputValidator iv             = new InputValidator("FormatCurrencyWithoutCurrencyCode");
            decimal        value          = iv.ValidateDecimal("CurrencyValue", sCurrencyValue);
            string         targetCurrency = iv.ValidateString("TargetCurrency", sTargetCurrency);

            decimal amt = Currency.Convert(value, Localization.GetPrimaryCurrency(), targetCurrency);

            String tmpS = String.Empty;
            // get currency specs for display control:
            String DisplaySpec         = Currency.GetDisplaySpec(targetCurrency);
            String DisplayLocaleFormat = Currency.GetDisplayLocaleFormat(targetCurrency);

            if (DisplaySpec.Length != 0)
            {
                CultureInfo ci = new CultureInfo(DisplayLocaleFormat);

                if (DisplaySpec.LastIndexOf(',') > DisplaySpec.LastIndexOf("."))
                {
                    ci.NumberFormat.CurrencyDecimalSeparator = ",";

                    if (DisplaySpec.LastIndexOf(".") > -1)
                    {
                        ci.NumberFormat.CurrencyGroupSeparator = ".";
                    }
                }

                if (!DisplaySpec.StartsWith("#"))
                {
                    int indexOf = DisplaySpec.IndexOf('#');

                    if (indexOf > -1)
                    {
                        ci.NumberFormat.CurrencySymbol = DisplaySpec.Substring(0, indexOf);
                    }
                }

                tmpS = amt.ToString("C", ci.NumberFormat);
            }
            else if (DisplayLocaleFormat.Length != 0)
            {
                CultureInfo formatter = new CultureInfo(DisplayLocaleFormat);

                // for debugging purposes
                if (CommonLogic.QueryStringUSInt("dec") > 0)
                {
                    int decimalPlaces = CommonLogic.QueryStringUSInt("dec");
                    formatter.NumberFormat.CurrencyDecimalDigits = decimalPlaces;
                }

                tmpS = amt.ToString("C", formatter);
                if (tmpS.StartsWith("("))
                {
                    tmpS = "-" + tmpS.Replace("(", "").Replace(")", "");
                }
            }
            else
            {
                tmpS = Localization.CurrencyStringForDisplayWithoutExchangeRate(amt, false);                 // use some generic default!
            }

            return(tmpS);
        }
Beispiel #2
0
 // this DOES NOT apply any exchange rates!!
 // it is FORMATTING ONLY!
 static public String ToString(decimal amt, String TargetCurrencyCode)
 {
     return(Localization.CurrencyStringForDisplayWithoutExchangeRate(amt, TargetCurrencyCode));
 }