示例#1
0
        public string ConvertAmountToWords(string code, string name, decimal amount)
        {
            CurrencyToTextParams currencyParams = new CurrencyToTextParams()
            {
                CurrencyAmount = amount,
                CurrencyCode   = code,
                CurrencyName   = name
            };

            return(ToText(currencyParams));
        }
示例#2
0
        public string ConvertAmountToWordsByCurrencyCode(string code, string amount)
        {
            decimal amountDecimal = 0;

            if (string.IsNullOrEmpty(amount))
            {
                amount = "0.00";
            }
            if (!Decimal.TryParse(amount, out amountDecimal))
            {
                amountDecimal = Convert.ToDecimal(amount);
            }
            CurrencyToTextParams currencyParams = new CurrencyToTextParams()
            {
                CurrencyAmount = amountDecimal,
                CurrencyCode   = code.ToUpper(),
                CurrencyName   = "pesos"
            };

            return(ToText(currencyParams));
        }
示例#3
0
        public string ToText(CurrencyToTextParams currencyParams)
        {
            char decimalSeparator = Convert.ToChar(Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);

            string[] amountSplit = currencyParams.CurrencyAmount.ToString().Split(decimalSeparator);

            if (amountSplit != null && amountSplit.Length == 1)
            {
                return(string.Format("{0} {1} {2} {3}",
                                     UpperCaseFirst(EvaluateNumber(Convert.ToInt64(amountSplit[0]))),
                                     (currencyParams.CurrencyName).ToLower(),
                                     "00/00",
                                     (currencyParams.CurrencyCode)));
            }
            else if (amountSplit != null && amountSplit.Length == 2)
            {
                return(string.Format("{0} {1} {2} {3}",
                                     UpperCaseFirst(EvaluateNumber(Convert.ToInt64(amountSplit[0]))),
                                     (currencyParams.CurrencyName).ToLower(),
                                     DecimalPartToText(amountSplit[1]),
                                     (currencyParams.CurrencyCode)));
            }
            return(string.Empty);
        }