Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static string CisloSlovy(this long cislo)
- {
- string result = string.Empty;
- if (cislo < 0)
- result = "mínus ";
- string numero = Math.Abs(cislo).ToString();
- if (numero.Length < 13)
- {
- //slovníky pro číslice na jednotlivých pozicích převáděného čísla
- Array[] slovnik = new Array[12];
- slovnik[0] = new[] { "", "jedna", "dvě", "tři", "čtyři", "pět", "šest", "sedm", "osm", "devět" };
- slovnik[1] = new[] { "", "", "dvacet", "třicet", "čtyřicet", "padesát", "šedesát", "sedmdesát", "osmdesát", "devadesát" };
- slovnik[2] = new[] { "", "sto", "dvě stě", "tři sta", "čtyři sta", "pět set", "šest set", "sedm set", "osm set", "devět set" };
- slovnik[3] = new[] { "tisíc", "jeden tisíc", "dva tisíce", "tři tisíce", "čtyři tisíce", "pět tisíc", "šest tisíc", "sedm tisíc", "osm tisíc", "devět tisíc" };
- slovnik[4] = new[] { "", "deset", "dvacet", "třicet", "čtyřicet", "padesát", "šedesát", "sedmdesát", "osmdesát", "devadesát" };
- slovnik[5] = new[] { "", "sto", "dvě stě", "tři sta", "čtyři sta", "pět set", "šest set", "sedm set", "osm set", "devět set" };
- slovnik[6] = new[] { "milionů", "jeden milion", "dva miliony", "tři miliony", "čtyři miliony", "pět milionů", "šest milionů", "sedm milionů", "osm milionů", "devět milionů" };
- slovnik[7] = new[] { "", "deset", "dvacet", "třicet", "čtyřicet", "padesát", "šedesát", "sedmdesát", "osmdesát", "devadesát" };
- slovnik[8] = new[] { "", "sto", "dvě stě", "tři sta", "čtyři sta", "pět set", "šest set", "sedm set", "osm set", "devět set" };
- slovnik[9] = new[] { "miliard", "jedna miliarda", "dvě miliardy", "tři miliardy", "čtyři miliardy", "pět miliard", "šest miliard", "sedm miliard", "osm miliard", "devět miliard" };
- slovnik[10] = new[] { "", "deset", "dvacet", "třicet", "čtyřicet", "padesát", "šedesát", "sedmdesát", "osmdesát", "devadesát" };
- slovnik[11] = new[] { "", "sto", "dvě stě", "tři sta", "čtyři sta", "pět set", "šest set", "sedm set", "osm set", "devět set" };
- var slovnik1019 = new[] { "deset", "jedenáct", "dvanáct", "třináct", "čtrnáct", "patnáct", "šestnáct", "sedmnáct", "osmnáct", "devatenáct" };
- for (var x = 0; x <= numero.Length - 1; x++)
- {
- //vypsání čísel obsahujících 10-19 ze slovníku 10-19
- if (((x == numero.Length - 2) || (x == numero.Length - 5) || (x == numero.Length - 8) || (x == numero.Length - 11)) && (numero[x] == '1'))
- {
- result += string.Format("{0} ", slovnik1019[int.Parse(numero[x + 1].ToString())]);
- var arr = slovnik[numero.Length - 2 - x];
- string value = (string)arr.GetValue(0);
- if (!string.IsNullOrEmpty(value))
- result += string.Format("{0} ", value);
- x++;
- continue;
- }
- //přeskočení skupin číslic 000 kvůli eliminaci duplicit milion tisíc, miliarda milion, ...
- if (numero.Length > 6 && (x == numero.Length - 4 || x == numero.Length - 7) && x - 2 >= 0 && numero.Substring(x - 2, 3).Equals("000"))
- {
- continue;
- }
- else
- {
- var arr = slovnik[numero.Length - 1 - x];
- string value = (string)arr.GetValue(int.Parse(numero[x].ToString()));
- if (!string.IsNullOrEmpty(value))
- result += string.Format("{0} ", value);
- }
- }
- }
- else
- result = numero;
- return result.TrimEnd();
- }
- public static string CastkaSlovy(this decimal castka)
- {
- if (castka > long.MaxValue)
- return castka.ToString();
- else
- {
- castka = Zaokrouhlovani.Round(castka, 2);
- long celaCastka = (long) decimal.Truncate(castka);
- long zbytek = (long) ((Math.Abs(castka) - Math.Abs(decimal.Truncate(castka))) * 100);
- string slovy = celaCastka.CisloSlovy();
- if (slovy.Length > 0)
- slovy = string.Format("{0} {1}", slovy, celaCastka.KorunSlovy());
- if (zbytek != decimal.Zero)
- slovy = string.Format("{0}{1}{2} haléřů", slovy, string.Empty.PadLeft(slovy.Length > 0 ? 1 : 0), zbytek.CisloSlovy());
- return slovy;
- }
- }
- public static string KorunSlovy(this long kc)
- {
- var slovnik = new[] { "korun", "koruna", "koruny", "koruny", "koruny" };
- if (slovnik.Length - 1 >= Math.Abs(kc))
- return slovnik[Math.Abs(kc)];
- else
- {
- if (kc.ToString().EndsWith("2"))
- return slovnik[2]; //např. padesát dvě koruny - výjimka; ostatní skloňujeme xx korun
- else
- return slovnik[0];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement