Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. static Dictionary<int, string> ShortScaleDictionary = new Dictionary<int, string>()
  2. {
  3. //{ 4, "K"},
  4. { 7, "Million"},
  5. { 10, "Billion"},
  6. { 13, "Trillion"},
  7. { 16, "Quadrillion"},
  8. { 19, "Quintillion"},
  9. { 22, "Sextillion"},
  10. { 25, "Septillion"},
  11. { 28, "Octillion"},
  12. { 31, "Nonillion"},
  13. { 34, "Decillion"},
  14. { 37, "Undecillion"},
  15. { 40, "Duodecillion"},
  16. { 43, "Tredecillion"},
  17. { 46, "Quattuordecillion"},
  18. { 49, "Quinquadecillion"},
  19. { 52, "Sedecillion"},
  20. { 55, "Septendecillion"},
  21. { 58, "Octodecillion"},
  22. { 61, "Novendecillion"},
  23. { 64, "Vigintillion"},
  24. { 67, "Unvigintillion"},
  25. { 70, "Duovigintillion"},
  26. { 73, "Tresvigintillion"},
  27. { 76, "Quattuorvigintillion"},
  28. { 79, "Quinquavigintillion"},
  29. { 82, "Sesvigintillion"},
  30. { 85, "Septemvigintillion"},
  31. { 88, "Octovigintillion"},
  32. { 91, "Novemvigintillion"},
  33. { 94, "Trigintillion"},
  34. { 97, "Untrigintillion"},
  35. { 100, "Duotrigintillion"},
  36. { 103, "Trestrigintillion"},
  37. { 106, "Quattuortrigintillion"},
  38. { 109, "Quinquatrigintillion"},
  39. { 112, "Sestrigintillion"},
  40. { 115, "Septentrigintillion"},
  41. { 118, "Octotrigintillion"},
  42. { 121, "Noventrigintillion"},
  43. { 124, "Quadragintillion"},
  44. { 127, "Quinquagintillion"},
  45. { 130, "Sexagintillion"},
  46. { 133, "Septuagintillion"},
  47. { 136, "Octogintillion"},
  48. { 139, "Nonagintillion"},
  49. { 142, "Centillion"},
  50. { 145, "Uncentillion"},
  51. { 148, "Decicentillion"},
  52. { 151, "Undecicentillion"},
  53. { 154, "Viginticentillion"},
  54. { 157, "Unviginticentillion"},
  55. { 160, "Trigintacentillion"},
  56. { 163, "Quadragintacentillion"},
  57. { 166, "Quinquagintacentillion"},
  58. { 169, "Sexagintacentillion"},
  59. { 172, "Septuagintacentillion"},
  60. { 175, "Octogintacentillion"},
  61. { 178, "Nonagintacentillion"},
  62. { 181, "Ducentillion"},
  63. { 184, "Trecentillion"},
  64. { 187, "Quadringentillion"},
  65. { 190, "Quingentillion"},
  66. { 193, "Sescentillion"},
  67. { 196, "Septingentillion"},
  68. { 199, "Octingentillion"},
  69. { 202, "Nongentillion"},
  70. { 205, "Millinillion"}
  71. };
  72.  
  73. public static string ConvertToShortScale(double inputNumber)
  74. {
  75.  
  76. long roundedInput = (long)Math.Round(inputNumber, 0);
  77. double roundedInputWithDigits = Math.Round(inputNumber, 3);
  78.  
  79.  
  80. int shortscalekeySubstract = roundedInput.ToString().Length % 3;
  81. int shortscalekey = roundedInput.ToString().Length - shortscalekeySubstract;
  82. if (shortscalekeySubstract != 0)
  83. shortscalekey += 1;
  84.  
  85. if (ShortScaleDictionary.ContainsKey(shortscalekey))
  86. return roundedInput/(Math.Pow(10,shortscalekey-1)) + " " +ShortScaleDictionary[shortscalekey];
  87. else
  88. {
  89. int i = shortscalekey-1;
  90. while(i > 0 )
  91. {
  92. if(ShortScaleDictionary.ContainsKey(i))
  93. return roundedInput / (Math.Pow(10, i-1)) + " " + ShortScaleDictionary[i];
  94. i--;
  95. }
  96.  
  97. }
  98. return inputNumber.ToString();
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement