本文整理汇总了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);
}
}
示例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;
}
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}