Ejemplo n.º 1
0
        public static bool TryParse(string str, out CurrencyValue value)
        {
            value = null;
            var match = _Regex.Match(str);

            if (!match.Success ||
                !decimal.TryParse(match.Groups[1].Value, out var v))
            {
                return(false);
            }

            var currency     = match.Groups.Last().Value.ToUpperInvariant();
            var currencyData = _CurrencyTable.GetCurrencyData(currency, false);

            if (currencyData == null)
            {
                return(false);
            }
            v     = Math.Round(v, currencyData.Divisibility);
            value = new CurrencyValue()
            {
                Value    = v,
                Currency = currency
            };
            return(true);
        }
Ejemplo n.º 2
0
        public static bool TryParse(string str, out CurrencyValue value)
        {
            value = null;
            if (string.IsNullOrEmpty(str))
            {
                return(false);
            }
            var match = _Regex.Match(str);

            if (!match.Success ||
                !decimal.TryParse(match.Groups[1].Value, NumberStyles.Any, CultureInfo.InvariantCulture, out var v))
            {
                return(false);
            }

            var currency     = match.Groups[match.Groups.Count - 1].Value.ToUpperInvariant();
            var currencyData = CurrencyNameTable.Instance.GetCurrencyData(currency, false);

            if (currencyData == null)
            {
                return(false);
            }
            v     = Math.Round(v, currencyData.Divisibility);
            value = new CurrencyValue()
            {
                Value    = v,
                Currency = currency
            };
            return(true);
        }