NumToWordsEn.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using System;
  2. using System.Text;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. namespace FastReport.Functions
  6. {
  7. internal class NumToWordsEn : NumToWordsBase
  8. {
  9. private static Dictionary<string, CurrencyInfo> currencyList;
  10. private static string[] fixedWords =
  11. {
  12. "", "one", "two", "three", "four", "five", "six",
  13. "seven", "eight", "nine", "ten", "eleven",
  14. "twelve", "thirteen", "fourteen", "fifteen",
  15. "sixteen", "seventeen", "eighteen", "nineteen"
  16. };
  17. private static string[] tens =
  18. {
  19. "", "ten", "twenty", "thirty", "forty", "fifty",
  20. "sixty", "seventy", "eighty", "ninety"
  21. };
  22. private static string[] hunds =
  23. {
  24. "", "one hundred", "two hundred", "three hundred", "four hundred",
  25. "five hundred", "six hundred", "seven hundred", "eight hundred", "nine hundred"
  26. };
  27. private static WordInfo thousands = new WordInfo("thousand");
  28. private static WordInfo millions = new WordInfo("million");
  29. private static WordInfo milliards = new WordInfo("billion");
  30. private static WordInfo trillions = new WordInfo("trillion");
  31. protected override string GetFixedWords(bool male, long value)
  32. {
  33. return fixedWords[value];
  34. }
  35. protected override string GetTen(bool male, long value)
  36. {
  37. return tens[value];
  38. }
  39. protected override string GetHund(bool male, long value)
  40. {
  41. return hunds[value / 100];
  42. }
  43. protected override WordInfo GetThousands()
  44. {
  45. return thousands;
  46. }
  47. protected override WordInfo GetMillions()
  48. {
  49. return millions;
  50. }
  51. protected override WordInfo GetMilliards()
  52. {
  53. return milliards;
  54. }
  55. protected override WordInfo GetTrillions()
  56. {
  57. return trillions;
  58. }
  59. protected override CurrencyInfo GetCurrency(string currencyName)
  60. {
  61. currencyName = currencyName.ToUpper();
  62. if (currencyName == "CAD")
  63. currencyName = "USD";
  64. return currencyList[currencyName];
  65. }
  66. protected override string GetZero()
  67. {
  68. return "zero";
  69. }
  70. protected override string GetMinus()
  71. {
  72. return "minus";
  73. }
  74. protected override string GetDecimalSeparator()
  75. {
  76. return "and ";
  77. }
  78. protected override string Get10_1Separator()
  79. {
  80. return "-";
  81. }
  82. protected override string Get100_10Separator()
  83. {
  84. return " and ";
  85. }
  86. static NumToWordsEn()
  87. {
  88. currencyList = new Dictionary<string, CurrencyInfo>();
  89. currencyList.Add("USD", new CurrencyInfo(
  90. new WordInfo("dollar", "dollars"),
  91. new WordInfo("cent", "cents")));
  92. currencyList.Add("EUR", new CurrencyInfo(
  93. new WordInfo("euro", "euros"),
  94. new WordInfo("cent", "cents")));
  95. currencyList.Add("GBP", new CurrencyInfo(
  96. new WordInfo("pound", "pounds"),
  97. new WordInfo("penny", "pence")));
  98. }
  99. }
  100. }