本文整理汇总了C#中MidpointRounding类的典型用法代码示例。如果您正苦于以下问题:C# MidpointRounding类的具体用法?C# MidpointRounding怎么用?C# MidpointRounding使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MidpointRounding类属于命名空间,在下文中一共展示了MidpointRounding类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: NumberToCurrencyText
public static string NumberToCurrencyText(decimal number, MidpointRounding midpointRounding = MidpointRounding.ToEven)
{
// Round the value just in case the decimal value is longer than two digits
number = Decimal.Round(number, 2, midpointRounding);
string wordNumber = String.Empty;
// Divide the number into the whole and fractional part strings
string[] arrNumber = number.ToString().Split('.');
// Get the whole number text
long wholePart = Int64.Parse(arrNumber[0]);
string strWholePart = NumberToText(wholePart);
// For amounts of zero dollars show 'No Dollars...' instead of 'Zero Dollars...'
wordNumber = (wholePart == 0 ? "No" : strWholePart) + (wholePart == 1 ? " Dollar and " : " Dollars and ");
// If the array has more than one element then there is a fractional part otherwise there isn't
// just add 'No Cents' to the end
if (arrNumber.Length > 1)
{
// If the length of the fractional element is only 1, add a 0 so that the text returned isn't,
// 'One', 'Two', etc but 'Ten', 'Twenty', etc.
long fractionPart = Int64.Parse((arrNumber[1].Length == 1 ? arrNumber[1] + "0" : arrNumber[1]));
string strFarctionPart = NumberToText(fractionPart);
wordNumber += (fractionPart == 0 ? " No" : strFarctionPart) + (fractionPart == 1 ? " Cent" : " Cents");
}
else
wordNumber += "No Cents";
return wordNumber;
}
开发者ID:FrankMedvedik,项目名称:coopcheck,代码行数:33,代码来源:NumberConverter.cs
示例2: Calculate
public static decimal Calculate(
Guid siteGuid,
Guid taxZoneGuid,
Guid taxClassGuid,
decimal taxableTotal,
int roundingDecimalPlaces,
MidpointRounding roundingMode)
{
decimal taxTotal = 0;
if (taxZoneGuid != Guid.Empty)
{
Collection<TaxRate> taxRates = TaxRate.GetTaxRates(siteGuid, taxZoneGuid);
if (taxRates.Count > 0)
{
foreach (TaxRate taxRate in taxRates)
{
if (taxClassGuid == taxRate.TaxClassGuid)
{
taxTotal += (taxRate.Rate * taxableTotal);
break;
}
}
}
}
return taxTotal;
}
开发者ID:joedavis01,项目名称:mojoportal,代码行数:29,代码来源:TaxCalculator.cs
示例3: Round
public static TimeSpan Round(this TimeSpan time, TimeSpan roundingInterval, MidpointRounding roundingType)
{
return new TimeSpan(
Convert.ToInt64(Math.Round(
time.Ticks / (decimal)roundingInterval.Ticks,
roundingType
)) * roundingInterval.Ticks
);
}
开发者ID:hlaubisch,项目名称:BrewBuddy,代码行数:9,代码来源:DateTimeExtensions.cs
示例4: Round
public int Round(
double value,
int digits,
MidpointRounding mode
)
{
int result = MathExtensions.Round(value, digits, mode);
return result;
// TODO: add assertions to method MathExtensionsTest.Round(Double, Int32, MidpointRounding)
}
开发者ID:RealDotNetDave,项目名称:dotNetTips.Utility,代码行数:10,代码来源:MathExtensionsTest.cs
示例5: ConvertAmount
public static double ConvertAmount(
double amount,
CurrencyCode originalCurrencyCode,
CurrencyCode targetCurrencyCode,
int decimalDigits = 2,
MidpointRounding midPointRounding = MidpointRounding.AwayFromZero)
{
double originalExchangeRate = GetExchangeRate(originalCurrencyCode);
double targetExchangeRate = GetExchangeRate(targetCurrencyCode);
double amount_USD = amount / originalExchangeRate;
double amount_TargetCurrency = Math.Round(amount_USD * targetExchangeRate, decimalDigits, midPointRounding);
return amount_TargetCurrency;
}
开发者ID:aliaksandr-trush,项目名称:csharp-automaton,代码行数:15,代码来源:MoneyTool.cs
示例6: SafeDivide
public static IEnumerable<Money> SafeDivide(this Money money, int shares, MidpointRounding rounding)
{
if (shares <= 1)
throw new ArgumentOutOfRangeException(nameof(shares), "Number of shares must be greater than 1");
decimal shareAmount = Math.Round(money.Amount / shares, (int)money.Currency.DecimalDigits, rounding);
decimal remainder = money.Amount;
for (int i = 0; i < shares - 1; i++)
{
remainder -= shareAmount;
yield return new Money(shareAmount, money.Currency);
}
yield return new Money(remainder, money.Currency);
}
开发者ID:JayT82,项目名称:NodaMoney-1,代码行数:16,代码来源:MoneyExtensions.SaveDivide.cs
示例7: InternalRound
[System.Security.SecuritySafeCritical] // auto-generated
private static unsafe double InternalRound(double value, int digits, MidpointRounding mode) {
if (Abs(value) < doubleRoundLimit) {
Double power10 = roundPower10Double[digits];
value *= power10;
if (mode == MidpointRounding.AwayFromZero) {
double fraction = SplitFractionDouble(&value);
if (Abs(fraction) >= 0.5d) {
value += Sign(fraction);
}
}
else {
// On X86 this can be inlined to just a few instructions
value = Round(value);
}
value /= power10;
}
return value;
}
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:19,代码来源:math.cs
示例8: Round
public static double Round(double value, int decimals, MidpointRounding midpointRounding)
{
var roundingMode = Java.Math.RoundingMode.UNNECESSARY;
switch (midpointRounding)
{
case MidpointRounding.AwayFromZero:
roundingMode = Java.Math.RoundingMode.HALF_UP;
break;
case MidpointRounding.ToEven:
roundingMode = Java.Math.RoundingMode.HALF_EVEN;
break;
}
var bigDecimal = new Java.Math.BigDecimal(value);
bigDecimal = bigDecimal.SetScale(decimals, roundingMode);
return bigDecimal.DoubleValue();
}
开发者ID:nguyenkien,项目名称:api,代码行数:19,代码来源:Math.cs
示例9: InternalRound
private unsafe static double InternalRound(double value, int digits, MidpointRounding mode)
{
if (Math.Abs(value) < Math.doubleRoundLimit)
{
double num = Math.roundPower10Double[digits];
value *= num;
if (mode == MidpointRounding.AwayFromZero)
{
double value2 = Math.SplitFractionDouble(&value);
if (Math.Abs(value2) >= 0.5)
{
value += (double)Math.Sign(value2);
}
}
else
{
value = Math.Round(value);
}
value /= num;
}
return value;
}
开发者ID:ChristianWulf,项目名称:CSharpKDMDiscoverer,代码行数:22,代码来源:Math.cs
示例10: Euro
/// <summary>Initializes a new instance of the <see cref="Money"/> structure in euro's.</summary>
/// <param name="amount">The Amount of money in euro.</param>
/// <param name="rounding">The rounding.</param>
/// <returns>A <see cref="Money"/> structure with EUR as <see cref="Currency"/>.</returns>
public static Money Euro(double amount, MidpointRounding rounding)
{
return new Money((decimal)amount, Currency.FromCode("EUR"), rounding);
}
开发者ID:JayT82,项目名称:NodaMoney-1,代码行数:8,代码来源:Money.FourMostUsedCurrencies.cs
示例11: Round
public static Decimal Round(Decimal d, int decimals, MidpointRounding mode) {
return Decimal.Round(d, decimals, mode);
}
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:3,代码来源:math.cs
示例12: RoundToInt
public static int RoundToInt(float f, MidpointRounding mode = MidpointRounding.AwayFromZero)
{
return (int) Math.Round(f, mode);
}
开发者ID:wooga,项目名称:ps_social_jam,代码行数:4,代码来源:MathUtil.cs
示例13: Round
/// <summary>
/// Rounds a value to a specified number of fractional digits.
/// </summary>
/// <param name="value">The input value.</param>
/// <param name="decimals">The number of decimal places in the return value.</param>
/// <param name="mode">
/// Specification for how to round <paramref name="value" /> if it is midway between two other numbers.
/// </param>
/// <returns>The output value.</returns>
public static decimal Round(this decimal value, int decimals = 0, MidpointRounding mode = MidpointRounding.ToEven)
{
return Math.Round(value, decimals, mode);
}
开发者ID:mkloubert,项目名称:Extensions.NET,代码行数:13,代码来源:Math.Round.cs
示例14: Round
public static F Round(int decimals, MidpointRounding mode) => x => Math.Round(x, decimals, mode);
开发者ID:atifaziz,项目名称:Partials,代码行数:1,代码来源:Floats.cs
示例15: Yen
/// <summary>Initializes a new instance of the <see cref="Money"/> structure in Japanese Yens.</summary>
/// <param name="amount">The Amount of money in euro.</param>
/// <param name="rounding">The rounding.</param>
/// <returns>A <see cref="Money"/> structure with JPY as <see cref="Currency"/>.</returns>
public static Money Yen(decimal amount, MidpointRounding rounding)
{
return new Money(amount, Currency.FromCode("JPY"), rounding);
}
开发者ID:JayT82,项目名称:NodaMoney-1,代码行数:8,代码来源:Money.FourMostUsedCurrencies.cs
示例16: USDollar
/// <summary>Initializes a new instance of the <see cref="Money"/> structure in US dollars.</summary>
/// <param name="amount">The Amount of money in US dollar.</param>
/// <param name="rounding">The rounding.</param>
/// <returns>A <see cref="Money"/> structure with USD as <see cref="Currency"/>.</returns>
public static Money USDollar(double amount, MidpointRounding rounding)
{
return new Money((decimal)amount, Currency.FromCode("USD"), rounding);
}
开发者ID:JayT82,项目名称:NodaMoney-1,代码行数:8,代码来源:Money.FourMostUsedCurrencies.cs
示例17: Round
/// <summary>
/// Rounds a decimal value to a specified number of fractional digits. A parameter specifies how to round the value if it is midway between two numbers.
/// </summary>
/// <param name="value">A double-precision floating-point number to be rounded.</param>
/// <param name="digits">The number of fractional digits in the return value.</param>
/// <param name="mode">Specification for how to round d if it is midway between two other numbers.</param>
public static double Round(this double value, int digits, MidpointRounding mode)
{
return System.Math.Round(value.ToString().Todouble(), digits.ToString().Toint(), mode);
}
开发者ID:Aragas,项目名称:Pokemon-3D-Server-Client,代码行数:10,代码来源:Math.cs
示例18: Round
/// <summary>
/// Rounds the specified value.
/// </summary>
/// <param name="value"> The value.</param>
/// <param name="digits">The digits.</param>
/// <param name="mode"> The mode.</param>
/// <returns>System.Int32.</returns>
/// <remarks>Code by: Lucas http://code.msdn.microsoft.com/LucasExtensions</remarks>
public static int Round(this double value, int digits, MidpointRounding mode)
{
Contract.Requires<ArgumentOutOfRangeException>(value >= double.MinValue && value <= double.MaxValue);
return Convert.ToInt32(System.Math.Round(value, digits, mode));
}
开发者ID:RealDotNetDave,项目名称:dotNetTips.Utility,代码行数:14,代码来源:MathExtensions.cs
示例19: PoundSterling
/// <summary>Initializes a new instance of the <see cref="Money"/> structure in British pounds.</summary>
/// <param name="amount">The Amount of money in Pound Sterling.</param>
/// <param name="rounding">The rounding.</param>
/// <returns>A <see cref="Money"/> structure with GBP as <see cref="Currency"/>.</returns>
public static Money PoundSterling(double amount, MidpointRounding rounding)
{
return new Money((decimal)amount, Currency.FromCode("GBP"), rounding);
}
开发者ID:JayT82,项目名称:NodaMoney-1,代码行数:8,代码来源:Money.FourMostUsedCurrencies.cs
示例20: RoundToNumberOfSignificantDigits
/// <summary>
/// Rounds a double number to the provided number of significant digits.
/// </summary>
/// <param name="x">The value to round.</param>
/// <param name="significantDigits">The number of significant digits.</param>
/// <returns>The number, rounded to the provided number of significant digits.</returns>
/// <param name="rounding">The rounding rule that should be applied.</param>
public static double RoundToNumberOfSignificantDigits(double x, int significantDigits, MidpointRounding rounding)
{
if (significantDigits < 0)
throw new ArgumentOutOfRangeException("significantDigits<0");
if (0 == x)
return 0;
int lg = (int)Math.Floor(Math.Log10(Math.Abs(x))) + 1;
if (lg < 0)
{
double fac = RMath.Pow(10, -lg);
double xpot = x * fac;
xpot = Math.Round(xpot, significantDigits, rounding);
return xpot / fac;
}
else
{
double fac = RMath.Pow(10, lg);
double xpot = x / fac;
xpot = Math.Round(xpot, significantDigits, rounding);
return xpot * fac;
}
}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:32,代码来源:Rounding.cs
注:本文中的MidpointRounding类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论