|
- using System;
- using UnityEngine;
-
- namespace SUISSEngine
- {
- [Serializable]
- public class CurrencyValue
- {
- public CurrencyValue()
- {
- }
-
- public CurrencyValue(string currency, decimal value)
- {
- this.currency = currency;
- this.value = value;
- this.stringValue = value.ToString();
- }
-
- public string Currency
- {
- get
- {
- return this.currency;
- }
- }
-
- public decimal Value
- {
- get
- {
- if (this.value == -79228162514264337593543950335m)
- {
- if (string.IsNullOrEmpty(this.stringValue))
- {
- this.value = 0.0m;
- this.stringValue = this.value.ToString();
- }
- else
- {
- this.value = decimal.Parse(this.stringValue);
- }
- }
- return this.value;
- }
- }
-
- public CurrencyValue Round(Currencies.RoundingMethod method, int precision)
- {
- decimal num = this.Value;
- decimal num2 = 1.0m;
- if (precision > 0)
- {
- for (int i = 0; i < precision; i++)
- {
- num2 *= 10.0m;
- }
- num *= num2;
- }
- if (method != Currencies.RoundingMethod.Nearest)
- {
- if (method != Currencies.RoundingMethod.Floor)
- {
- if (method == Currencies.RoundingMethod.Ceiling)
- {
- num = Math.Ceiling(num);
- }
- }
- else
- {
- num = Math.Floor(num);
- }
- }
- else
- {
- num = Math.Round(num);
- }
- if (precision > 0)
- {
- num /= num2;
- }
- return new CurrencyValue(this.currency, num);
- }
-
- public override int GetHashCode()
- {
- if (this.hash == 0)
- {
- this.hash = this.ToString().GetHashCode();
- }
- return this.hash;
- }
-
- public override string ToString()
- {
- return string.Format("{0}:{1}", this.Currency, this.Value);
- }
-
- public override bool Equals(object obj)
- {
- return obj is CurrencyValue && object.Equals(((CurrencyValue)obj).Currency, this.Currency) && ((CurrencyValue)obj).Value == this.Value;
- }
-
- [SerializeField]
- private string currency;
-
- [SerializeField]
- private string stringValue;
-
- private decimal value = decimal.MinValue;
-
- private int hash;
- }
- }
|