Esempio n. 1
0
        public Liczba(double liczba, Rodzaj rodzaj, int ExcludePowersOver = -1)
        {
            if (ExcludePowersOver == -1)
            {
                ExcludePowersOver = MaxPower;
            }
            bool ApplyOneForm = (liczba == 1);

            Text = "";
            foreach (KeyValuePair <int, string> v in e)
            {
                if (v.Key > ExcludePowersOver)
                {
                    continue;
                }
                double power = Math.Pow(10, v.Key);
                if (double.IsInfinity(power))
                {
                    continue;
                }
                double t = Math.Floor(liczba / power);
                if (t == 1)
                {
                    Text += v.Value + ' ';
                }
                else if (t > 0)
                {
                    Mianownik m = new Mianownik(v.Value);
                    Text += new Liczba(t, m.JakiRodzaj(), ExcludePowersOver).Text + ' ' + m.GetNumberForm(t) + ' ';
                }
                liczba -= t * power;
            }
            if (liczba >= 100)
            {
                double t = Math.Floor(liczba / 100);
                Text   += setki[(int)t - 1] + ' ';
                liczba -= t * 100;
            }
            if (liczba >= 11 && liczba <= 19)
            {
                Text += nastki[(int)liczba - 11] + ' ';
            }
            else
            {
                if (liczba >= 10)
                {
                    double t = Math.Floor(liczba / 10);
                    Text   += dziesiątki[(int)t - 1] + ' ';
                    liczba -= t * 10;
                }
                if (liczba > 0)
                {
                    if (ApplyOneForm)
                    {
                        if (rodzaj == Rodzaj.Żeński)
                        {
                            Text += "jedna ";
                        }
                        else if (rodzaj == Rodzaj.Nijaki)
                        {
                            Text += "jedno ";
                        }
                        else
                        {
                            Text += cyfry[(int)liczba] + ' ';
                        }
                    }
                    else if (liczba == 2 && rodzaj == Rodzaj.Żeński)
                    {
                        Text += "dwie ";
                    }
                    else
                    {
                        Text += cyfry[(int)liczba] + ' ';
                    }
                }
            }
            if (Text.Length == 0)
            {
                Text = cyfry[0];
            }
            else
            {
                Text = Text.Remove(Text.Length - 1);
            }
        }
Esempio n. 2
0
        public Liczba(string liczba, Rodzaj rodzaj, int ExcludePowersOver = -1)
        {
            if (ExcludePowersOver == -1)
            {
                ExcludePowersOver = MaxPower;
            }
            bool ApplyOneForm = (liczba == "1");
            int  digits       = liczba.Length;

            Text = "";
            foreach (KeyValuePair <int, string> v in e)
            {
                if (v.Key > ExcludePowersOver)
                {
                    continue;
                }
                if (digits > v.Key)
                {
                    string t = liczba.Substring(0, digits - v.Key);
                    int    n = 0;
                    int.TryParse(t.Last().ToString(), out n);
                    if (t.Length > 1 && t.First() != '0' || n > 2)
                    {
                        Mianownik m = new Mianownik(v.Value);
                        Text += new Liczba(t, m.JakiRodzaj(), ExcludePowersOver).Text + ' ' + m.GetNumberForm(t) + ' ';
                    }
                    else if (n == 1)
                    {
                        Text += v.Value + ' ';
                    }
                    liczba = liczba.Substring(digits - v.Key);
                    digits = liczba.Length;
                }
            }
            int number;

            if (int.TryParse(liczba, out number))
            {
                if (number >= 100)
                {
                    int t = number / 100;
                    Text   += setki[t - 1] + ' ';
                    number -= t * 100;
                }
                if (number >= 11 && number <= 19)
                {
                    Text += nastki[number - 11] + ' ';
                }
                else
                {
                    if (number >= 10)
                    {
                        int t = number / 10;
                        Text   += dziesiątki[t - 1] + ' ';
                        number -= t * 10;
                    }
                    if (number > 0)
                    {
                        if (ApplyOneForm)
                        {
                            if (rodzaj == Rodzaj.Żeński)
                            {
                                Text += "jedna ";
                            }
                            else if (rodzaj == Rodzaj.Nijaki)
                            {
                                Text += "jedno ";
                            }
                            else
                            {
                                Text += cyfry[number] + ' ';
                            }
                        }
                        else if (number == 2 && rodzaj == Rodzaj.Żeński)
                        {
                            Text += "dwie ";
                        }
                        else
                        {
                            Text += cyfry[number] + ' ';
                        }
                    }
                }
                if (Text.Length == 0)
                {
                    Text = cyfry[0];
                }
                else
                {
                    Text = Text.Remove(Text.Length - 1);
                }
            }
            else
            {
                Text = "(nieprawidłowa liczba)";
            }
        }