Exemple #1
0
        public Price ToPriceEntity()
        {
            Price entity = new Price(this.normalizedPrice, this.normalizedValue, this.numeratorUnit, this.denominator);

            return entity;
        }
Exemple #2
0
 public static Price Subtract(Price price1, int points, bool isReciprocal)
 {
     if (isReciprocal)
     {
         return price1 + points;
     }
     else
     {
         return price1 - points;
     }
 }
Exemple #3
0
        public static Price Create(double value, int numeratorUnit, int denominator, bool isGreatThan)
        {
            Price price = new Price(value, numeratorUnit, denominator);

            if (isGreatThan && price.normalizedValue < value)
            {
                price += 1;
            }
            else if (!isGreatThan && price.normalizedValue > value)
            {
                price -= 1;
            }

            return price;
        }
Exemple #4
0
 public static int Compare(Price price1, Price price2, bool isReciprocal)
 {
     if (price1 == null && price2 == null)
     {
         return 0;
     }
     else if (price1 != null)
     {
         return price1.CompareTo(price2) * (isReciprocal ? -1 : 1);
     }
     else
     {
         return price2.CompareTo(price1) * (isReciprocal ? 1 : -1);
     }
 }
Exemple #5
0
        public static Price Avg(Price price1, Price price2)
        {
            if (price1.numeratorUnit != price2.numeratorUnit || price1.denominator != price2.denominator)
            {
                throw new ArgumentException("Prices is not the same type");
            }

            return CreateInstance((price1.normalizedValue + price2.normalizedValue) / 2, price1.numeratorUnit, price1.denominator);
        }
Exemple #6
0
        public static Price Adjust(Price price1, int points)
        {
            if (price1 == null)
            {
                return null;
            }
            int pointsLen = points.ToString().Length;
            int pointsDenominator = (int)Math.Pow(10, pointsLen);

            double pointsDouble = (double)points;
            if (pointsDenominator > price1.denominator && price1.denominator != 1)
            {
                pointsDouble = Math.Floor(pointsDouble / (pointsDenominator / price1.denominator));
                pointsDenominator = price1.denominator;
            }

            double Price1 = (Math.Floor(((price1.normalizedValue * price1.denominator) / pointsDenominator) * pointsDenominator + pointsDouble)) / price1.denominator;

            //double price = (zPrice + pointsDouble) / price1._Denominator;
            //double price = price1._NormalizedValue + (double)points / price1._Denominator;
            return CreateInstance(Price1, price1.numeratorUnit, price1.denominator);
        }