Beispiel #1
0
        private void Form(uint count, Plural plural, string id = "")
        {
            if (id != "")
            {
                language = id;
            }

            PluralProc func = MultiPattern.GetProc(new CultureInfo(language));

            Assert.IsTrue(func(count, (int)count, 0, 0, 0, 0) == plural);
        }
Beispiel #2
0
        private static string Format(double value, AbbreviatedNumberForm form, int precision, AbbreviationRule[] rules)
        {
            foreach (var rule in rules)
            {
                if (rule.Range <= value)
                {
                    var range  = rule.Range;
                    var result = rule.Value;
                    var p      = result.IndexOf('0');
                    result = result.Remove(p, 1);

                    while ((result != "") && (result[p] == '0'))
                    {
                        result = result.Remove(p, 1);
                        range  = range / 10;
                    }

                    string str;
                    double displayValue;

                    if (result != "")
                    {
                        str          = GetStr(value / range, precision);
                        displayValue = Convert.ToDouble(str);
                    }
                    else
                    {
                        str          = GetNotAbbreviatedStr(value, form, precision);
                        displayValue = value;
                    }

                    uint count = (uint)Math.Round(displayValue);

                    if (displayValue == count)
                    {
                        //var proc = MultiPattern.GetIndexProc();
                        var plural = MultiPattern.GetProc()(count, (int)count, 0, 0, 0, 0);

                        if (plural != rule.Plural)
                        {
                            // Wrong plural form. Find the correct one and get abbreviation again
                            var newRule = Find(rule.Range, plural, rules);

                            if (newRule != null)
                            {
                                range  = newRule.Range;
                                result = newRule.Value;
                                p      = result.IndexOf('0');
                                result = result.Remove(p, 1);

                                while ((result != "") && (result[p] == '0'))
                                {
                                    result = result.Remove(p, 1);
                                    range  = range / 10;
                                }

                                str = GetStr(value / range, precision);
                            }
                        }
                    }

                    result = result.Substring(0, p) + str + result.Substring(p);
                    p      = result.IndexOf('¤');

                    if (p >= 0)
                    {
                        result = result.Substring(0, p) + NumberFormatInfo.CurrentInfo.CurrencySymbol + result.Substring(p + 1);
                    }

                    return(result);
                }
            }

            return(GetNotAbbreviatedStr(value, form, precision));
        }