NumToWordsNl.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. using System;
  2. using System.Text;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. namespace FastReport.Functions
  6. {
  7. internal class NumToWordsNl : NumToWordsBase
  8. {
  9. private static Dictionary<string, CurrencyInfo> currencyList;
  10. private static string[] fixedWords =
  11. {
  12. "", "een", "twee", "drie", "vier", "vijf", "zes",
  13. "zeven", "acht", "negen", "tien", "elf",
  14. "twaalf", "dertien", "veertien", "vijftien",
  15. "zestien", "zeventien", "achttien", "negentien"
  16. };
  17. private static string[] tens =
  18. {
  19. "", "tien", "twintig", "dertig", "veertig", "vijftig",
  20. "zestig", "zeventig", "tachtig", "negentig"
  21. };
  22. private static string[] hunds =
  23. {
  24. "", "honderd", "tweehonderd", "driehonderd", "vierhonderd",
  25. "vijfhonderd", "zeshonderd", "zevenhonderd", "achthonderd", "negenhonderd"
  26. };
  27. private static WordInfo thousands = new WordInfo("duizend");
  28. private static WordInfo millions = new WordInfo("miljoen");
  29. private static WordInfo milliards = new WordInfo("miljard");
  30. private static WordInfo trillions = new WordInfo("trillion");
  31. protected override string Str1000(long value, WordInfo info, int counter)
  32. {
  33. long val = value % 1000;
  34. if (val == 0)
  35. return "";
  36. StringBuilder r = new StringBuilder();
  37. // add hundred
  38. string hund = GetHund(info.male, val);
  39. if (hund != "")
  40. r.Append(hund);
  41. // decide whether to use the 100-10 separator or not
  42. string sep100_10 = Get100_10Separator();
  43. if (value < 1000 && hund == "")
  44. sep100_10 = "";
  45. val = val % 100;
  46. if (val < GetFixedWordsCount())
  47. {
  48. // val is less than fixed words count (usually 20), get fixed words
  49. string frac20 = GetFixedWords(info.male, val);
  50. if (frac20 != "")
  51. r.Append(sep100_10 + frac20);
  52. }
  53. else
  54. {
  55. // val is greater than fixed words count (usually 20), get tens separately
  56. string ten = GetTen(info.male, val / 10);
  57. string frac10 = GetFixedWords(info.male, val % 10);
  58. string sep10_1 = "en";
  59. if (val % 10 == 2 || val % 10 == 3)
  60. sep10_1 = "ën";
  61. // decide whether to use 10-1 separator or not
  62. if (ten != "" && frac10 != "")
  63. r.Append(sep100_10 + frac10 + sep10_1 + ten);
  64. else if (ten != "")
  65. r.Append(sep100_10 + ten);
  66. else if (frac10 != "")
  67. r.Append(sep100_10 + frac10);
  68. }
  69. // add currency/group word
  70. if (counter != 2)
  71. r.Append(" ");
  72. r.Append(Case(value, info));
  73. // make the result starting with letter and ending with space
  74. if (r.Length != 0)
  75. r.Append(" ");
  76. return r.ToString().TrimStart(' ');
  77. }
  78. protected override string GetFixedWords(bool male, long value)
  79. {
  80. return fixedWords[value];
  81. }
  82. protected override string GetTen(bool male, long value)
  83. {
  84. return tens[value];
  85. }
  86. protected override string GetHund(bool male, long value)
  87. {
  88. return hunds[value / 100];
  89. }
  90. protected override WordInfo GetThousands()
  91. {
  92. return thousands;
  93. }
  94. protected override WordInfo GetMillions()
  95. {
  96. return millions;
  97. }
  98. protected override WordInfo GetMilliards()
  99. {
  100. return milliards;
  101. }
  102. protected override WordInfo GetTrillions()
  103. {
  104. return trillions;
  105. }
  106. protected override CurrencyInfo GetCurrency(string currencyName)
  107. {
  108. currencyName = currencyName.ToUpper();
  109. if (currencyName == "CAD")
  110. currencyName = "USD";
  111. return currencyList[currencyName];
  112. }
  113. protected override string GetZero()
  114. {
  115. return "nul";
  116. }
  117. protected override string GetMinus()
  118. {
  119. return "min";
  120. }
  121. protected override string GetDecimalSeparator()
  122. {
  123. return "en ";
  124. }
  125. static NumToWordsNl()
  126. {
  127. currencyList = new Dictionary<string, CurrencyInfo>();
  128. currencyList.Add("USD", new CurrencyInfo(
  129. new WordInfo("dollar", "dollar"),
  130. new WordInfo("cent", "cent")));
  131. currencyList.Add("EUR", new CurrencyInfo(
  132. new WordInfo("euro", "euro"),
  133. new WordInfo("cent", "cent")));
  134. currencyList.Add("GBP", new CurrencyInfo(
  135. new WordInfo("pound", "pound"),
  136. new WordInfo("penny", "penny")));
  137. }
  138. }
  139. }