示例#1
0
        public static string GetResult(string input, PercentUnits mode)
        {
            var result = float.Parse(input, CultureInfo.InvariantCulture.NumberFormat);

            if (mode == PercentUnits.Percent)
            {
                return((result / 100).ToString());
            }
            else
            {
                return((result * 100).ToString() + "%");
            }
        }
        private void ChangeToDecimal(object sender, SelectionChangedEventArgs e)
        {
            var selectedIndex = percentOrDecimal.SelectedIndex;

            if (selectedIndex == 0)
            {
                SelectPercent = PercentUnits.Percent;
            }
            else if (selectedIndex == 1)
            {
                SelectPercent = PercentUnits.Decimal;
            }
        }
        public static PercentValue StrToPercentValue(string value)
        {
            var ss = _doubleRege.Split(value).Where(t =>
            {
                var s = t.Trim();
                return(!(s == "," || s == "" || s == ","));
            });
            string num  = "";
            string unit = "";

            foreach (var s in ss)
            {
                if (_doubleRege.IsMatch(s))
                {
                    num = s;
                    continue;
                }
                if (_unitRegex.IsMatch(s))
                {
                    unit = s;
                    continue;
                }
            }

            PercentUnits units = PercentUnits.hundredth;

            if (unit.ToLower() == "%")
            {
                units = PercentUnits.hundredth;;
            }

            if (double.TryParse(num, out double dd))
            {
                return(new PercentValue(dd, units));
            }
            return(null);
        }
 public PercentValue(double value, PercentUnits units = PercentUnits.hundredth)
 {
     _value = value;
     _units = units;
 }