当前位置: 首页>>代码示例>>C#>>正文


C# Money.Convert方法代码示例

本文整理汇总了C#中Money.Convert方法的典型用法代码示例。如果您正苦于以下问题:C# Money.Convert方法的具体用法?C# Money.Convert怎么用?C# Money.Convert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Money的用法示例。


在下文中一共展示了Money.Convert方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestConverter

		public void TestConverter()
		{
			var money1 = new Money(12.34, CurrencyCodes.USD);
			var money2 = new Money(12.34, CurrencyCodes.ZAR);
			Money.Converter = new ConverterMock();

			var money3 = money1.Convert(CurrencyCodes.ZAR);

			Assert.AreEqual(money3.CurrencyCode, money2.CurrencyCode);
			Assert.AreNotEqual(money3, money2);
			Assert.IsTrue(money3 > money2);
			Assert.IsTrue(money1 != money3);
			Assert.AreNotEqual(money3, money1);

            // comparing apples to oranges possible with Converter!
            // Will only return a match if the Converter has the same rate for from -> to and (inverted) to -> from
            Money.AllowImplicitConversion = true;
            var m1To3 = Money.Converter.GetRate(money1.CurrencyCode, money3.CurrencyCode, DateTime.Now);
            var m3To1 = Money.Converter.GetRate(money3.CurrencyCode, money1.CurrencyCode, DateTime.Now);
            if (m1To3 == 1d / m3To1)
            {
                Assert.IsTrue(money3 == money1);
                Assert.IsTrue(money1 == money3);
                Assert.AreEqual(money3, money1);
            }
            else
            {
                Assert.IsFalse(money3 == money1);
                Assert.IsFalse(money1 == money3);
                Assert.AreNotEqual(money3, money1);
            }
        }
开发者ID:Padhraic,项目名称:Utile.Money,代码行数:32,代码来源:ConversionTest.cs

示例2: ConvertAmount

        public static string ConvertAmount(decimal quantity, int curFromId, int curToId, DateTime date)
        {
            using (IDalSession session = NHSessionFactory.CreateSession())
            {
                ICurrency curFrom = InstrumentMapper.GetCurrency(session, curFromId);
                ICurrency curTo = InstrumentMapper.GetCurrency(session, curToId);
                Money amount = new Money(quantity, curFrom);

                Money convAmount = null;
                if (Util.IsNotNullDate(date))
                    convAmount = amount.Convert(curTo, Side.Buy, date, session);
                else
                    convAmount = amount.Convert(curTo);

                return convAmount.DisplayString;
            }
        }
开发者ID:kiquenet,项目名称:B4F,代码行数:17,代码来源:XEConverterAdapter.cs

示例3: TestConversion

		public void TestConversion()
		{
			var money1 = new Money(12.34, CurrencyCodes.USD);
			var money2 = new Money(12.34, CurrencyCodes.ZAR);

			var money3 = money1.Convert(CurrencyCodes.ZAR, 7.8);

			Assert.AreEqual(money3.CurrencyCode, money2.CurrencyCode);
			Assert.AreNotEqual(money3, money2);
			Assert.IsTrue(money3 > money2);
			// No way to check if Rands are equal to dollars
			Assert.IsTrue(money1 != money3);
		}
开发者ID:Padhraic,项目名称:Utile.Money,代码行数:13,代码来源:ConversionTest.cs

示例4: ConvertToOrderCurrency

 /// <summary>
 /// Converts an amount to the currency of a given order.
 /// </summary>
 /// <param name="fee">The amount to convert.</param>
 /// <param name="client">The order whose currency to convert to.</param>
 /// <returns></returns>
 protected Money ConvertToOrderCurrency(Money fee, ICommClient client)
 {
     if (fee != null)
     {
         if ((ICurrency)fee.Underlying != client.OrderCurrency)
             fee = fee.Convert(client.OrderCurrency);
         return fee.Round();
     }
     else
         return new Money(0, client.OrderCurrency);
 }
开发者ID:kiquenet,项目名称:B4F,代码行数:17,代码来源:CommCalc.cs

示例5: PredictSize

        /// <summary>
        /// Get the educated guess of the size of a instrument for a amount of money
        /// </summary>
        /// <param name="inputAmount"></param>
        /// <returns></returns>
        public override PredictedSize PredictSize(Money inputAmount)
        {
            PredictedSize retVal = new PredictedSize(PredictedSizeReturnValue.NoRate);
            Money amount;

            if (CurrentPrice != null)
            {
                retVal.RateDate = CurrentPrice.Date;
                if (inputAmount.Underlying.Equals(CurrentPrice.Price.Underlying))
                    retVal.Size = inputAmount.CalculateSize(CurrentPrice.Price);
                else
                {
                    amount = inputAmount.Convert(CurrentPrice.Price.Underlying);
                    retVal.Size = amount.CalculateSize(CurrentPrice.Price);
                }
                retVal.Rate = currentPrice.Price.ToString();
            }
            return retVal;
        }
开发者ID:kiquenet,项目名称:B4F,代码行数:24,代码来源:TradeableInstrument.cs

示例6: calculateSize

 private static InstrumentSize calculateSize(Money amount, Price price, IList<IHistoricalExRate> exrates, DateTime date)
 {
     if (!price.Underlying.IsBase)
     {
         IHistoricalExRate exrate = exrates.Where(x => x.Currency.Key == price.Underlying.Key && x.RateDate == date).FirstOrDefault();
         if (exrate == null)
             throw new ApplicationException(string.Format("Exchange rate for {0} on {1} is missing.", price.Underlying.Symbol, date.ToShortDateString()));
         Money convAmt = amount.Convert(exrate.Rate, price.Underlying);
         return convAmt / price;
     }
     else
         return amount / price;
 }
开发者ID:kiquenet,项目名称:B4F,代码行数:13,代码来源:RebalanceIndicatorAdapter.cs


注:本文中的Money.Convert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。