Beispiel #1
0
 public static decimal Round(decimal amount, Rounding rounding)
 {
     var floatRounded = Math.Round(amount, rounding.FloatPrecision, MidpointRounding.AwayFromZero);
     return rounding.IntegerRounding != null
         ? IntegerRound(amount, rounding.IntegerRounding.Value)
         : floatRounded;
 }
        public ExchangeRate CalculateFromConversionRate(ConversionRate conversionRate, DateTime timstampUtc, Rounding rounding)
        {
            Argument.NotNull(conversionRate, "conversionRate");

            var baseCurrency = _currencyRepository.Find(conversionRate.Conversion.From);
            if (baseCurrency == null)
            {
                var message = string.Format("Can't find currency [{0}] in the database.", conversionRate.Conversion.From);
                throw new InvalidOperationException(message);
            }
            var foreignCurrency = _currencyRepository.Find(conversionRate.Conversion.To);
            if (foreignCurrency == null)
            {
                var message = string.Format("Can't find currency [{0}] in the database.", conversionRate.Conversion.To);
                throw new InvalidOperationException(message);
            }
            var buyRate = MoneyMath.Round(conversionRate.Rate * (decimal) Randomizer.FromRange(_settings.BuyRateCoefficientRange), rounding);
            var sellRate = MoneyMath.Round(conversionRate.Rate * (decimal) Randomizer.FromRange(_settings.SellRateCoefficientRange), rounding);
            return ExchangeRate.Create(baseCurrency, foreignCurrency, buyRate, sellRate, timstampUtc);
        }