NumberUtil.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using UnityEngine;
  2. namespace GFGGame
  3. {
  4. public class NumberUtil
  5. {
  6. public static string GetChiniseNumberText(int num)
  7. {
  8. int numInUnit = 0;
  9. int numInTen = 0;
  10. string strInUnit = "";
  11. string strInTen = "";
  12. if (num <= 10)
  13. {
  14. return GameConst.CHINESE_NUMBER[num - 1];
  15. }
  16. else if (num < 20)
  17. {
  18. numInUnit = num - 10;
  19. strInUnit = GameConst.CHINESE_NUMBER[numInUnit - 1];
  20. return "十" + strInUnit;
  21. }
  22. else if (num < 100)
  23. {
  24. numInTen = Mathf.FloorToInt(num / 10);
  25. strInTen = GameConst.CHINESE_NUMBER[numInTen - 1];
  26. numInUnit = num % 10;
  27. if (numInUnit == 0)
  28. {
  29. return strInTen + "十";
  30. }
  31. else
  32. {
  33. strInUnit = GameConst.CHINESE_NUMBER[numInUnit - 1];
  34. return strInTen + "十" + strInUnit;
  35. }
  36. }
  37. return "未知";
  38. }
  39. public static string GetChiniseNumberWeekText(int num)
  40. {
  41. if (num >= 0 && num < GameConst.CHINESE_NUMBER.Length)
  42. {
  43. return GameConst.CHINESE_WEEK_NUMBER[num];
  44. }
  45. return "未知";
  46. }
  47. public static string ChangeNumberUnit(int num, int unit = 10000)
  48. {
  49. int count = num / unit;
  50. if (count > 0)
  51. {
  52. return string.Format("{0}万", count);
  53. }
  54. return num.ToString();
  55. }
  56. }
  57. }