本文整理汇总了C#中Money.Round方法的典型用法代码示例。如果您正苦于以下问题:C# Money.Round方法的具体用法?C# Money.Round怎么用?C# Money.Round使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Money
的用法示例。
在下文中一共展示了Money.Round方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Round_DecimalPlaces_using_Money_RoundingMode
public void Round_DecimalPlaces_using_Money_RoundingMode(RoundingMode roundingMode, DecimalPlaces decimalPlaces, decimal value, decimal expected)
{
// specify different DecimalPlaces for Money ctor to ensure the argument value is used
Money money = new Money("ZAR", value, roundingMode, DecimalPlaces.Nine);
Money actual = money.Round(decimalPlaces);
Assert.That(actual.Amount == expected);
}
示例2: Round_RoundingMode_using_Money_DecimalPlaces
public void Round_RoundingMode_using_Money_DecimalPlaces(RoundingMode roundingMode, DecimalPlaces decimalPlaces, decimal value, decimal expected)
{
// specify different RoundingMode for Money ctor to ensure the argument value is used
RoundingMode moneyMode = roundingMode == 0 ? roundingMode + 1 : roundingMode - 1;
Money money = new Money("ZAR", value, moneyMode, decimalPlaces);
Money actual = money.Round(roundingMode);
Assert.That(actual.Amount == expected);
}
示例3: 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);
}
示例4: Round_no_arguments_using_Money_defaults
public void Round_no_arguments_using_Money_defaults(RoundingMode roundingMode, DecimalPlaces decimalPlaces, decimal value, decimal expected)
{
Money money = new Money("ZAR", value, roundingMode, decimalPlaces);
Money actual = money.Round();
Assert.That(actual.Amount == expected);
}
示例5: CalculateBackwards
/// <summary>
/// Calculates a fee so that the fee plus the net amount (of the order) equals the gross amount.
/// </summary>
/// <param name="grossAmount">The gross amount.</param>
/// <param name="fee">The calculated fee (<b>out</b> parameter).</param>
/// <returns><b>true</b> if fee could be calculated (net amount fell on this line), <b>false</b> if not.</returns>
public virtual bool CalculateBackwards(Money grossAmount, out Money fee)
{
bool result = false;
Money nettAmount;
Money check;
Money comAmount = grossAmount;
if (!comAmount.Underlying.Equals(this.Parent.CommCurrency))
comAmount = comAmount.Convert(this.Parent.CommCurrency);
Money fixedSetup = Parent.FixedSetup + StaticChargeAmount;
fee = (((comAmount.Abs() - fixedSetup) * (FeePercentage / 100M)) / (1M + (FeePercentage / 100M))) + fixedSetup;
fee = fee.Round();
check = Parent.MinValue;
if (check != null && check.IsNotZero && fee < check)
{
fee = check;
}
else
{
check = Parent.MaxValue;
if (check != null && check.IsNotZero && fee > check)
{
fee = check;
}
}
if (comAmount.Sign)
{
nettAmount = comAmount - fee;
}
else
{
nettAmount = comAmount + fee;
}
// Check if within range
if (Envelops(nettAmount.Abs()))
result = true;
return result;
}