当前位置:   article > 正文

Unity3D--大额数值单位转换_unity 将10000转化为xxw

unity 将10000转化为xxw
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace Test
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. Console.WriteLine(Numdispose("45555555207"));
  13. string[] symbol = {"个", "千", "百万", "十亿", "万亿" };
  14. Console.WriteLine(NumUnit(45555555207, symbol));
  15. Console.WriteLine(FormatNum(45555555207, 3));
  16. Console.ReadKey();
  17. }
  18. /// <summary>
  19. /// 数字换算
  20. /// </summary>
  21. /// <param name="num"></param>
  22. /// <returns></returns>
  23. public static string Numdispose(string num)
  24. {
  25. string[] symbol = { "K", "M", "B", "T", "aa", "ab", "ac", "ad" };
  26. string str1 = string.Empty;
  27. string str2 = string.Empty;
  28. if (num.Length > 6)
  29. {
  30. int a = (num.Length - 6) / 3;
  31. str1 = num.Substring(0, (num.Length - (3 * (a + 1))));
  32. int b = num.Length - (3 * (a + 1));
  33. str2 = num[b].ToString();
  34. if (int.Parse(str2) >= 5) str1 = (int.Parse(str1) + 1).ToString();
  35. if (str1.Length > 3) return str1.Insert(str1.Length - 3, ",") + symbol[a];
  36. return str1 + symbol[a];
  37. }
  38. if (num.Length > 3 && num.Length < 7)
  39. {
  40. return num.Insert(num.Length - 3, ",");
  41. }
  42. return num;
  43. }
  44. public static string NumUnit(double num, string[] unitArray)
  45. {
  46. double tempNum = num;
  47. if (tempNum < 10000)
  48. {
  49. return num.ToString("0");
  50. }
  51. int unitIndex = 0;
  52. while (tempNum / 10000 / 100 >= 1)
  53. {
  54. unitIndex++;
  55. if (unitIndex >= unitArray.Length)
  56. {
  57. unitIndex = unitArray.Length - 1;
  58. break;
  59. }
  60. tempNum /= 100;
  61. }
  62. return (tempNum / 10000).ToString("0.00") + unitArray[unitIndex];
  63. }
  64. /// <summary>
  65. /// 数值转换 效果最好
  66. /// </summary>
  67. /// <param name="coin">数值</param>
  68. /// <param name="fixNum">保留小数点数</param>
  69. /// <returns></returns>
  70. public static string FormatNum(decimal coin, int fixNum)
  71. {
  72. string textTemp = string.Empty;
  73. string text3 = "f" + fixNum.ToString();
  74. if (coin >= 100000000000000000000000000m)
  75. {
  76. textTemp = (coin / 100000000000000000000000000m).ToString(text3) + "ae";
  77. }
  78. else if (coin >= 1000000000000000000000000m)
  79. {
  80. textTemp = (coin / 1000000000000000000000000m).ToString(text3) + "ad";
  81. }
  82. else if (coin >= 1000000000000000000000m)
  83. {
  84. textTemp = (coin / 1000000000000000000000m).ToString(text3) + "ac";
  85. }
  86. else if (coin >= new decimal(1000000000000000000L))
  87. {
  88. textTemp = (coin / new decimal(1000000000000000000L)).ToString(text3) + "ab";
  89. }
  90. else if (coin >= new decimal(1000000000000000L))
  91. {
  92. textTemp = (coin / new decimal(1000000000000000L)).ToString(text3) + "aa";
  93. }
  94. else if (coin >= new decimal(1000000000000L))
  95. {
  96. textTemp = (coin / new decimal(1000000000000L)).ToString(text3) + "t";
  97. }
  98. else if (coin >= 1000000000m)
  99. {
  100. textTemp = (coin / 1000000000m).ToString(text3) + "b";
  101. }
  102. else if (coin >= 1000000m)
  103. {
  104. textTemp = (coin / 1000000m).ToString(text3) + "m";
  105. }
  106. else if (coin >= 1000m)
  107. {
  108. textTemp = (coin / 1000m).ToString(text3) + "k";
  109. }
  110. else
  111. {
  112. textTemp = coin.ToString("0");
  113. }
  114. return textTemp;
  115. }
  116. }
  117. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/108432
推荐阅读
相关标签
  

闽ICP备14008679号