您不能選擇超過 %s 個話題 話題必須以字母或數字為開頭,可包含連接號 ('-') 且最長為 35 個字
 
 
 

115 行
2.1 KiB

  1. using System;
  2. using UnityEngine;
  3. namespace SUISSEngine
  4. {
  5. [Serializable]
  6. public class CurrencyValue
  7. {
  8. public CurrencyValue()
  9. {
  10. }
  11. public CurrencyValue(string currency, decimal value)
  12. {
  13. this.currency = currency;
  14. this.value = value;
  15. this.stringValue = value.ToString();
  16. }
  17. public string Currency
  18. {
  19. get
  20. {
  21. return this.currency;
  22. }
  23. }
  24. public decimal Value
  25. {
  26. get
  27. {
  28. if (this.value == -79228162514264337593543950335m)
  29. {
  30. if (string.IsNullOrEmpty(this.stringValue))
  31. {
  32. this.value = 0.0m;
  33. this.stringValue = this.value.ToString();
  34. }
  35. else
  36. {
  37. this.value = decimal.Parse(this.stringValue);
  38. }
  39. }
  40. return this.value;
  41. }
  42. }
  43. public CurrencyValue Round(Currencies.RoundingMethod method, int precision)
  44. {
  45. decimal num = this.Value;
  46. decimal num2 = 1.0m;
  47. if (precision > 0)
  48. {
  49. for (int i = 0; i < precision; i++)
  50. {
  51. num2 *= 10.0m;
  52. }
  53. num *= num2;
  54. }
  55. if (method != Currencies.RoundingMethod.Nearest)
  56. {
  57. if (method != Currencies.RoundingMethod.Floor)
  58. {
  59. if (method == Currencies.RoundingMethod.Ceiling)
  60. {
  61. num = Math.Ceiling(num);
  62. }
  63. }
  64. else
  65. {
  66. num = Math.Floor(num);
  67. }
  68. }
  69. else
  70. {
  71. num = Math.Round(num);
  72. }
  73. if (precision > 0)
  74. {
  75. num /= num2;
  76. }
  77. return new CurrencyValue(this.currency, num);
  78. }
  79. public override int GetHashCode()
  80. {
  81. if (this.hash == 0)
  82. {
  83. this.hash = this.ToString().GetHashCode();
  84. }
  85. return this.hash;
  86. }
  87. public override string ToString()
  88. {
  89. return string.Format("{0}:{1}", this.Currency, this.Value);
  90. }
  91. public override bool Equals(object obj)
  92. {
  93. return obj is CurrencyValue && object.Equals(((CurrencyValue)obj).Currency, this.Currency) && ((CurrencyValue)obj).Value == this.Value;
  94. }
  95. [SerializeField]
  96. private string currency;
  97. [SerializeField]
  98. private string stringValue;
  99. private decimal value = decimal.MinValue;
  100. private int hash;
  101. }
  102. }