Ejemplo n.º 1
0
        public Price ToPriceEntity()
        {
            Price entity = new Price(this.normalizedPrice, this.normalizedValue, this.numeratorUnit, this.denominator);

            return entity;
        }
Ejemplo n.º 2
0
 public static Price Subtract(Price price1, int points, bool isReciprocal)
 {
     if (isReciprocal)
     {
         return price1 + points;
     }
     else
     {
         return price1 - points;
     }
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }