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; }
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; }
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 ); }
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) }
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; }
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); }
[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; }
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(); }
/// <summary>Divide the Money in shares with a specific ratio, without losing Money.</summary> /// <param name="money">The <see cref="T:NodaMoney.Money"/> instance.</param> /// <param name="ratios">The number of shares as an array of ratios.</param> /// <param name="rounding">The rounding mode.</param> /// <returns>An <see cref="IEnumerable{Money}"/> of Money.</returns> /// <exception cref="System.ArgumentOutOfRangeException">shares;Number of shares must be greater than 1</exception> public static IEnumerable<Money> SafeDivide(this Money money, int[] ratios, MidpointRounding rounding) { if (ratios.Any(ratio => ratio < 1)) throw new ArgumentOutOfRangeException("ratios", "All ratios must be greater or equal than 1"); decimal remainder = money.Amount; for (int i = 0; i < ratios.Length - 1; i++) { decimal ratioAmount = Math.Round( money.Amount * ratios[i] / ratios.Sum(), (int)money.Currency.DecimalDigits, rounding); remainder -= ratioAmount; yield return new Money(ratioAmount, money.Currency); } yield return new Money(remainder, money.Currency); }
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; }
/// <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); }
/// <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="d">A decimal number to be rounded.</param> /// <param name="decimals">The number of decimal places 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 decimal Round(this decimal d, int decimals, MidpointRounding mode) { return System.Math.Round(d.ToString().Todecimal(), decimals.ToString().Toint(), mode); }
public Centiwatt Round(MidpointRounding mode) => new Centiwatt(Math.Round(_value, mode));
/// <summary> /// 保留<paramref name="precision"/>位小数,中国式 四舍五入,ToEven银行家算法 /// </summary> /// <param name="value">数值</param> /// <param name="precision">精度</param> /// <param name="mode">舍入模式</param> /// <returns></returns> public static double MathRound(this double value, int precision, MidpointRounding mode = MidpointRounding.AwayFromZero) { return(Math.Round(value, precision, mode)); }
public static double?Round(this double?value, int digits, MidpointRounding mode) => value?.Round(digits, mode);
public static TimeSpan RoundToEnd(this TimeSpan time, TimeSpan roundingInterval, MidpointRounding roundingType) { return(new TimeSpan( Convert.ToInt64(Math.Round( ((time.Ticks + (roundingInterval.Ticks / 2)) - 1) / (decimal)roundingInterval.Ticks, roundingType )) * roundingInterval.Ticks )); }
public static Decimal Round(Decimal d, int decimals, MidpointRounding mode) { return(Decimal.Round(d, decimals, mode)); }
public static decimal Round(this decimal number, MidpointRounding mode) { return(Math.Round(number, mode)); }
public static double Round(this double number, MidpointRounding mode) { return(Math.Round(number, mode)); }
public static float Round(this float number, MidpointRounding mode) { return((float)Math.Round(number, mode)); }
/// <summary> /// Returns a matrix where each element is rounded to the nearest integral value. /// </summary> /// <param name="value">A matrix.</param> /// <param name="digits">The number of fractional digits in the return value.</param> /// <param name="mode">Specification for how to round value if it is midway between two other numbers.</param> /// <returns>The result of rounding value.</returns> public static Matrix2x4f Round(Matrix2x4f value, int digits, MidpointRounding mode) { return(new Matrix2x4f(Functions.Round(value.M11, digits, mode), Functions.Round(value.M21, digits, mode), Functions.Round(value.M12, digits, mode), Functions.Round(value.M22, digits, mode), Functions.Round(value.M13, digits, mode), Functions.Round(value.M23, digits, mode), Functions.Round(value.M14, digits, mode), Functions.Round(value.M24, digits, mode))); }
public static Decimal Round(Decimal d, MidpointRounding mode) { return(Round(d, 0, mode)); }
/// <summary> /// Returns a size where each component is rounded to the nearest integral value. /// </summary> /// <param name="value">A size.</param> /// <param name="digits">The number of fractional digits in the return value.</param> /// <param name="mode">Specification for how to round value if it is midway between two other numbers.</param> /// <returns>The result of rounding value.</returns> public static Size2d Round(Size2d value, int digits, MidpointRounding mode) { return(new Size2d(Functions.Round(value.Width, digits, mode), Functions.Round(value.Height, digits, mode))); }
/// <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); }
/// <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; } }
/// <summary> /// Rounds this value to the nearest hundred. /// </summary> public static int RoundToHundred(this decimal value, MidpointRounding m) => (int)Math.Round(value / 100m, m) * 100;
/// <summary> /// 保留<paramref name="precision"/>位小数,默认AwayFromZero模式,中国式 四舍五入,ToEven银行家算法 /// </summary> /// <param name="value">数值</param> /// <param name="precision">精度</param> /// <param name="mode">舍入模式</param> /// <returns></returns> public static float MathRound(this float value, int precision, MidpointRounding mode = MidpointRounding.AwayFromZero) { return((float)Math.Round(value, precision, mode)); }
public static double Round(double value, int digits, MidpointRounding mode) { return(CSMath.Round(value, digits, mode)); }
public static SizeInt32 Round(SizeFloat size, MidpointRounding mode = 1) => new SizeInt32((int)Math.Round((double)size.width, mode), (int)Math.Round((double)size.height, mode));
public override void Visit(Function function) { var args = new FunctionArgs { Parameters = new Expression[function.Expressions.Length] }; // Don't call parameters right now, instead let the function do it as needed. // Some parameters shouldn't be called, for instance, in a if(), the "not" value might be a division by zero // Evaluating every value could produce unexpected behaviour for (int i = 0; i < function.Expressions.Length; i++) { args.Parameters[i] = new Expression(function.Expressions[i], _options); args.Parameters[i].EvaluateFunction += EvaluateFunction; args.Parameters[i].EvaluateParameter += EvaluateParameter; // Assign the parameters of the Expression to the arguments so that custom Functions and Parameters can use them args.Parameters[i].Parameters = Parameters; } // Calls external implementation OnEvaluateFunction(IgnoreCase ? function.Identifier.Name.ToLower() : function.Identifier.Name, args); // If an external implementation was found get the result back if (args.HasResult) { Result = args.Result; return; } switch (function.Identifier.Name.ToLower()) { #region Abs case "abs": CheckCase("Abs", function.Identifier.Name); if (function.Expressions.Length != 1) { throw new ArgumentException("Abs() takes exactly 1 argument"); } bool useDouble = (_options & EvaluateOptions.UseDoubleForAbsFunction) == EvaluateOptions.UseDoubleForAbsFunction; if (useDouble) { Result = Math.Abs(Convert.ToDouble( Evaluate(function.Expressions[0])) ); } else { Result = Math.Abs(Convert.ToDecimal( Evaluate(function.Expressions[0])) ); } break; #endregion #region Acos case "acos": CheckCase("Acos", function.Identifier.Name); if (function.Expressions.Length != 1) { throw new ArgumentException("Acos() takes exactly 1 argument"); } Result = Math.Acos(Convert.ToDouble(Evaluate(function.Expressions[0]))); break; #endregion #region Asin case "asin": CheckCase("Asin", function.Identifier.Name); if (function.Expressions.Length != 1) { throw new ArgumentException("Asin() takes exactly 1 argument"); } Result = Math.Asin(Convert.ToDouble(Evaluate(function.Expressions[0]))); break; #endregion #region Atan case "atan": CheckCase("Atan", function.Identifier.Name); if (function.Expressions.Length != 1) { throw new ArgumentException("Atan() takes exactly 1 argument"); } Result = Math.Atan(Convert.ToDouble(Evaluate(function.Expressions[0]))); break; #endregion #region Ceiling case "ceiling": CheckCase("Ceiling", function.Identifier.Name); if (function.Expressions.Length != 1) { throw new ArgumentException("Ceiling() takes exactly 1 argument"); } Result = Math.Ceiling(Convert.ToDouble(Evaluate(function.Expressions[0]))); break; #endregion #region Cos case "cos": CheckCase("Cos", function.Identifier.Name); if (function.Expressions.Length != 1) { throw new ArgumentException("Cos() takes exactly 1 argument"); } Result = Math.Cos(Convert.ToDouble(Evaluate(function.Expressions[0]))); break; #endregion #region Exp case "exp": CheckCase("Exp", function.Identifier.Name); if (function.Expressions.Length != 1) { throw new ArgumentException("Exp() takes exactly 1 argument"); } Result = Math.Exp(Convert.ToDouble(Evaluate(function.Expressions[0]))); break; #endregion #region Floor case "floor": CheckCase("Floor", function.Identifier.Name); if (function.Expressions.Length != 1) { throw new ArgumentException("Floor() takes exactly 1 argument"); } Result = Math.Floor(Convert.ToDouble(Evaluate(function.Expressions[0]))); break; #endregion #region IEEERemainder case "ieeeremainder": CheckCase("IEEERemainder", function.Identifier.Name); if (function.Expressions.Length != 2) { throw new ArgumentException("IEEERemainder() takes exactly 2 arguments"); } Result = Math.IEEERemainder(Convert.ToDouble(Evaluate(function.Expressions[0])), Convert.ToDouble(Evaluate(function.Expressions[1]))); break; #endregion #region Log case "log": CheckCase("Log", function.Identifier.Name); if (function.Expressions.Length != 2) { throw new ArgumentException("Log() takes exactly 2 arguments"); } Result = Math.Log(Convert.ToDouble(Evaluate(function.Expressions[0])), Convert.ToDouble(Evaluate(function.Expressions[1]))); break; #endregion #region Log10 case "log10": CheckCase("Log10", function.Identifier.Name); if (function.Expressions.Length != 1) { throw new ArgumentException("Log10() takes exactly 1 argument"); } Result = Math.Log10(Convert.ToDouble(Evaluate(function.Expressions[0]))); break; #endregion #region Pow case "pow": CheckCase("Pow", function.Identifier.Name); if (function.Expressions.Length != 2) { throw new ArgumentException("Pow() takes exactly 2 arguments"); } Result = Math.Pow(Convert.ToDouble(Evaluate(function.Expressions[0])), Convert.ToDouble(Evaluate(function.Expressions[1]))); break; #endregion #region Round case "round": CheckCase("Round", function.Identifier.Name); if (function.Expressions.Length != 2) { throw new ArgumentException("Round() takes exactly 2 arguments"); } MidpointRounding rounding = (_options & EvaluateOptions.RoundAwayFromZero) == EvaluateOptions.RoundAwayFromZero ? MidpointRounding.AwayFromZero : MidpointRounding.ToEven; Result = Math.Round(Convert.ToDouble(Evaluate(function.Expressions[0])), Convert.ToInt16(Evaluate(function.Expressions[1])), rounding); break; #endregion #region Sign case "sign": CheckCase("Sign", function.Identifier.Name); if (function.Expressions.Length != 1) { throw new ArgumentException("Sign() takes exactly 1 argument"); } Result = Math.Sign(Convert.ToDouble(Evaluate(function.Expressions[0]))); break; #endregion #region Sin case "sin": CheckCase("Sin", function.Identifier.Name); if (function.Expressions.Length != 1) { throw new ArgumentException("Sin() takes exactly 1 argument"); } Result = Math.Sin(Convert.ToDouble(Evaluate(function.Expressions[0]))); break; #endregion #region Sqrt case "sqrt": CheckCase("Sqrt", function.Identifier.Name); if (function.Expressions.Length != 1) { throw new ArgumentException("Sqrt() takes exactly 1 argument"); } Result = Math.Sqrt(Convert.ToDouble(Evaluate(function.Expressions[0]))); break; #endregion #region Tan case "tan": CheckCase("Tan", function.Identifier.Name); if (function.Expressions.Length != 1) { throw new ArgumentException("Tan() takes exactly 1 argument"); } Result = Math.Tan(Convert.ToDouble(Evaluate(function.Expressions[0]))); break; #endregion #region Truncate case "truncate": CheckCase("Truncate", function.Identifier.Name); if (function.Expressions.Length != 1) { throw new ArgumentException("Truncate() takes exactly 1 argument"); } Result = Math.Truncate(Convert.ToDouble(Evaluate(function.Expressions[0]))); break; #endregion #region Max case "max": CheckCase("Max", function.Identifier.Name); if (function.Expressions.Length != 2) { throw new ArgumentException("Max() takes exactly 2 arguments"); } object maxleft = Evaluate(function.Expressions[0]); object maxright = Evaluate(function.Expressions[1]); Result = Numbers.Max(maxleft, maxright); break; #endregion #region Min case "min": CheckCase("Min", function.Identifier.Name); if (function.Expressions.Length != 2) { throw new ArgumentException("Min() takes exactly 2 arguments"); } object minleft = Evaluate(function.Expressions[0]); object minright = Evaluate(function.Expressions[1]); Result = Numbers.Min(minleft, minright); break; #endregion #region if case "if": CheckCase("if", function.Identifier.Name); if (function.Expressions.Length != 3) { throw new ArgumentException("if() takes exactly 3 arguments"); } bool cond = Convert.ToBoolean(Evaluate(function.Expressions[0])); Result = cond ? Evaluate(function.Expressions[1]) : Evaluate(function.Expressions[2]); break; #endregion #region in case "in": CheckCase("in", function.Identifier.Name); if (function.Expressions.Length < 2) { throw new ArgumentException("in() takes at least 2 arguments"); } object parameter = Evaluate(function.Expressions[0]); bool evaluation = false; // Goes through any values, and stop whe one is found for (int i = 1; i < function.Expressions.Length; i++) { object argument = Evaluate(function.Expressions[i]); if (CompareUsingMostPreciseType(parameter, argument) == 0) { evaluation = true; break; } } Result = evaluation; break; #endregion default: throw new ArgumentException("Function not found", function.Identifier.Name); } }
/// <summary> /// 泛型转Decimal,默认保留两位小数,默认【采用4舍6入5取偶】 /// <para>采用Banker's rounding(银行家算法),即:四舍六入五取偶。事实上这也是IEEE的规范。</para> /// <para>备注:<see cref="MidpointRounding.AwayFromZero"/>可以用来实现传统意义上的"四舍五入"。</para> /// </summary> /// <param name="value">要转的值</param> /// <param name="digits">保留的小数位数</param> /// <param name="returnValue">失败时返回的值</param> /// <param name="mode">可选择模式</param> /// <returns></returns> public static decimal ToRoundDec <T>(this T value, int digits = 2, decimal returnValue = 0, MidpointRounding mode = MidpointRounding.ToEven) => Math.Round(value.ToDec(returnValue), digits, mode);
public Hectohertz Round(MidpointRounding mode) => new Hectohertz(Math.Round(_value, mode));
public SquareAttometre Round(MidpointRounding mode) => new SquareAttometre(Math.Round(_value, mode));
/// <summary> /// Returns a complex number whose components are rounded to the nearest multiple of <paramref name="roundTo"/> /// </summary> /// <param name="complex">Complex number to round</param> /// <param name="roundTo">Number whose multiple to round to</param> /// <returns></returns> public static Complex RoundTo(this Complex complex, double roundTo, MidpointRounding rounding = MidpointRounding.AwayFromZero) => new Complex(Math.Round(complex.Real / roundTo, rounding) * roundTo, Math.Round(complex.Imaginary / roundTo, rounding) * roundTo);
public static int RoundToInt(float f, MidpointRounding mode = MidpointRounding.AwayFromZero) { return (int) Math.Round(f, mode); }
public static decimal Round(decimal?value, int decimals = 5, MidpointRounding mode = MidpointRounding.AwayFromZero) { return(Math.Round(value ?? 0, decimals, mode)); }
/// <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); }
public Money RoundToNearestInt(MidpointRounding mode) { return(new Money(Math.Round(Amount, mode), CurrencyCode)); }
/// <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); }
public static double Round(double value, MidpointRounding mode) { return Round(value, 0, mode); }
/// <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); }
public static Decimal Round(Decimal d, int decimals, MidpointRounding mode) { return Decimal.Round(d, decimals, mode); }
public RoundingJsonConverter(int precision, MidpointRounding rounding) { _precision = precision; _rounding = rounding; }
public static double Round(double value, MidpointRounding mode) { return(Round(value, 0, mode)); }
public static double Round(double value, int digits, MidpointRounding mode) { if ((digits < 0) || (digits > maxRoundingDigits)) throw new ArgumentOutOfRangeException("digits", Environment.GetResourceString("ArgumentOutOfRange_RoundingDigits")); if (mode < MidpointRounding.ToEven || mode > MidpointRounding.AwayFromZero) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidEnumValue", mode, "MidpointRounding"), "mode"); } Contract.EndContractBlock(); return InternalRound(value, digits, mode); }
public static F Round(int decimals, MidpointRounding mode) => x => Math.Round(x, decimals, mode);
/// <summary> /// Rounds a value to a specified number of fractional digits. /// </summary> /// <param name="value">The input value.</param> /// <param name="digits">The number of fractional digits 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 double Round(this double value, int digits = 0, MidpointRounding mode = MidpointRounding.ToEven) { return Math.Round(value, digits, mode); }
/// <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); }
public Money Round(MidpointRounding mode) { Currency currency = Currency.Get(CurrencyCode); return(Round(currency.SignificantDecimalDigits, mode)); }
private static double RoundDipForDisplayMode(double value, double pixelsPerDip, MidpointRounding midpointRounding) { return(Math.Round(value *pixelsPerDip, midpointRounding) / pixelsPerDip); }
/// <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)); }
public Money Round(int decimals, MidpointRounding mode) { return(new Money(Math.Round(Amount, decimals, mode), CurrencyCode)); }
public static Func<int, F> Round(MidpointRounding mode) => decimals => x => Math.Round(x, decimals, mode);
public static extern decimal Round(decimal d, MidpointRounding mode);
/// <summary> /// Rounds a value to a specified number of fractional digits. /// </summary> /// <param name="value">The input value.</param> /// <param name="digits">The number of fractional digits 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 or <see langword="null" /> if <paramref name="value" /> /// is <see langword="null" />.</returns> public static double? Round(this double? value, int digits = 0, MidpointRounding mode = MidpointRounding.ToEven) { return value.HasValue ? Round(value.Value, digits, mode) : (double?)null; }
public extern decimal ToDecimalPlaces(int dp, MidpointRounding rm);
/// <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 or <see langword="null" /> if <paramref name="value" /> /// is <see langword="null" />.</returns> public static decimal? Round(this decimal? value, int decimals = 0, MidpointRounding mode = MidpointRounding.ToEven) { return value.HasValue ? Round(value.Value, decimals, mode) : (decimal?)null; }
public extern string ToExponential(int dp, MidpointRounding rm);
public static Scalar Round(Scalar value, int digits, MidpointRounding mode) { return (Scalar)Math.Round(value, digits, mode); }
public extern string ToFixed(int dp, MidpointRounding rm);