NumToWordsPl.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using System;
  2. using System.Text;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. namespace FastReport.Functions
  6. {
  7. internal class NumToWordsPl : NumToWordsBase
  8. {
  9. private static Dictionary<string, CurrencyInfo> currencyList;
  10. private static string[] fixedWords =
  11. {
  12. "", "jeden", "dwa", "trzy", "cztery", "pięć", "sześć",
  13. "siedem", "osiem", "dziewięć", "dziesięć", "jedenaście",
  14. "dwanaście", "trzynaście", "czternaście", "piętnaście",
  15. "szesnaście", "siedemnaście", "osiemnaście", "dziewiętnaście"
  16. };
  17. private static string[] tens =
  18. {
  19. "", "dziesięć", "dwadzieścia", "trzydzieści", "czterdzieści", "pięćdziesiąt",
  20. "sześćdziesiąt", "siedemdziesiąt", "osiemdziesiąt", "dziewięćdziesiąt"
  21. };
  22. private static string[] hunds =
  23. {
  24. "", "sto", "dwieście", "trzysta", "czterysta",
  25. "czterysta", "sześćset", "siedemset", "osiemset", "dziewięćset"
  26. };
  27. private static WordInfo thousands = new WordInfo(false, "tysiąc", "tysiące", "tysięcy");
  28. private static WordInfo millions = new WordInfo(true, "milion", "miliony", "milionów");
  29. private static WordInfo milliards = new WordInfo(true, "miliard", "miliardy", "miliardów");
  30. private static WordInfo trillions = new WordInfo(true, "bilion", "biliony", "bilionów");
  31. protected override string GetFixedWords(bool male, long value)
  32. {
  33. string result = fixedWords[value];
  34. if (!male)
  35. {
  36. if (value == 1)
  37. return "jedna";
  38. if (value == 2)
  39. return "dwie";
  40. }
  41. return result;
  42. }
  43. protected override string GetTen(bool male, long value)
  44. {
  45. return tens[value];
  46. }
  47. protected override string GetHund(bool male, long value)
  48. {
  49. return hunds[value / 100];
  50. }
  51. protected override WordInfo GetThousands()
  52. {
  53. return thousands;
  54. }
  55. protected override WordInfo GetMillions()
  56. {
  57. return millions;
  58. }
  59. protected override WordInfo GetMilliards()
  60. {
  61. return milliards;
  62. }
  63. protected override WordInfo GetTrillions()
  64. {
  65. return trillions;
  66. }
  67. protected override CurrencyInfo GetCurrency(string currencyName)
  68. {
  69. currencyName = currencyName.ToUpper();
  70. if (currencyName == "RUR")
  71. currencyName = "RUB";
  72. return currencyList[currencyName];
  73. }
  74. protected override string GetZero()
  75. {
  76. return "zero";
  77. }
  78. protected override string GetMinus()
  79. {
  80. return "minus";
  81. }
  82. protected override string Case(long value, WordInfo info)
  83. {
  84. value = value % 100;
  85. if (value > GetFixedWordsCount())
  86. value = value % 10;
  87. switch (value)
  88. {
  89. case 1:
  90. return info.one;
  91. case 2:
  92. case 3:
  93. case 4:
  94. return info.two;
  95. default:
  96. return info.many;
  97. }
  98. }
  99. static NumToWordsPl()
  100. {
  101. currencyList = new Dictionary<string, CurrencyInfo>(1);
  102. currencyList.Add("PLN", new CurrencyInfo(
  103. new WordInfo(true, "złoty", "zlote", "złotych"),
  104. new WordInfo(false, "grosz", "grosze", "groszy")));
  105. }
  106. }
  107. }