public void Should_return_Rounded_Negative_1000_for_Decimal_with_99_Cents() { decimal testInputs = -1000.99m; Int32 testResult = IntRounding.RoundDown(testInputs); Assert.AreEqual(TEST_NEG_RESULT_NUMBER, testResult); }
public void Should_return_Rounded_1000_for_Decimal_with_60_Cents() { decimal testInputs = 1000.60m; Int32 testResult = IntRounding.RoundDown(testInputs); Assert.AreEqual(TEST_POS_RESULT_NUMBER, testResult); }
public void Should_return_Rounded_1000_for_Decimal_with_49_Cents() { decimal testInputs = 1000.49m; Int32 testResult = IntRounding.RoundToInt(testInputs); Assert.AreEqual(TEST_POS_RESULT_NUMBER_DOWN, testResult); }
public void Should_return_Rounded_Negative_1000_for_Decimal_1090_with_60_Cents() { decimal testInputs = -1090.60m; Int32 testResult = IntRounding.NearRoundUp(testInputs, TEST_NEAREST_NUMBER); Assert.AreEqual(TEST_NEG_RESULT_NUMBER, testResult); }
public void Should_return_Rounded_1000_for_Decimal_1090_with_99_Cents() { decimal testInputs = 1090.99m; Int32 testResult = IntRounding.NearRoundUp(testInputs, TEST_NEAREST_NUMBER); Assert.AreEqual(TEST_POS_RESULT_NUMBER, testResult); }
public static Int32 RebateResult(decimal rebateBasis, decimal rebateApply, decimal rebateClaim) { decimal afterApply = decimal.Subtract(rebateBasis, rebateApply); decimal afterClaim = Math.Max(0m, decimal.Subtract(rebateClaim, afterApply)); decimal rebateResult = decimal.Subtract(rebateClaim, afterClaim); return(IntRounding.RoundToInt(rebateResult)); }
// ChildrenBonus public Int32 StatementChildrenBonus(MonthPeriod period, Int32 advancesTax, Int32 payerRebate, Int32 childrenAllowance, Int32 childrenRebate) { decimal bonusMaxChild = PeriodMaximumValidAmountOfTaxBonus(period); decimal bonusMinChild = PeriodMinimumValidAmountOfTaxBonus(period); decimal bonusForChild = decimal.Negate(Math.Min(0, childrenRebate - childrenAllowance)); decimal bonusResult = TaxingOperations.LimitToMinMax(bonusForChild, bonusMinChild, bonusMaxChild); return(IntRounding.RoundToInt(bonusResult)); }
private static Vector3Int ApplyRounding(Vector3 value, IntRounding rounding) { switch (rounding) { default: case IntRounding.Regular: return(new Vector3Int(Mathf.RoundToInt(value.x), Mathf.RoundToInt(value.y), Mathf.RoundToInt(value.z))); case IntRounding.Floor: return(new Vector3Int(Mathf.FloorToInt(value.x), Mathf.FloorToInt(value.y), Mathf.FloorToInt(value.z))); case IntRounding.Ceiling: return(new Vector3Int(Mathf.CeilToInt(value.x), Mathf.CeilToInt(value.y), Mathf.CeilToInt(value.z))); } }
// ---------------------------------------------------------------------------------------------------------------------------------------------- private static int ApplyRounding(float value, IntRounding rounding) { switch (rounding) { default: case IntRounding.Regular: return(Mathf.RoundToInt(value)); case IntRounding.Floor: return(Mathf.FloorToInt(value)); case IntRounding.Ceiling: return(Mathf.CeilToInt(value)); } }
/// <summary> /// Lerp from Vector3Int a to b by the factor t (range 0 to 1) with rounding. /// Uses smooth (ease-in and -out) interpolation as a default, but supports many different interpolation curves. /// </summary> /// <param name="from">The start value (t = 0)</param> /// <param name="to">The target value (t = 1)</param> /// <param name="t">The interpolation value (range 0 to 1)</param> /// <param name="type">The interpolation to use</param> /// <param name="rounding">The type of rounding to apply to the result.</param> /// <returns>The interpolated value between from and to.</returns> public static Vector3Int Lerp(Vector3Int from, Vector3Int to, float t, InterpolationTypes type = InterpolationTypes.Smooth, IntRounding rounding = IntRounding.Regular) { t = ApplyLerp(t, type); return(ApplyRounding(Vector3.Lerp(from, to, t), rounding)); }
/// <summary> /// Lerp from int a to b by the factor t (range 0 to 1) with rounding. /// Uses smooth (ease-in and -out) interpolation as a default, but supports many different interpolation curves. /// </summary> /// <param name="from">The start value (t = 0)</param> /// <param name="to">The target value (t = 1)</param> /// <param name="t">The interpolation value (range 0 to 1)</param> /// <param name="type">The interpolation to use</param> /// <param name="rounding">The type of rounding to apply to the result.</param> /// <returns>The interpolated value between from and to rounded to the nearest integer.</returns> public static int Lerp(int from, int to, float t, InterpolationTypes type = InterpolationTypes.Smooth, IntRounding rounding = IntRounding.Regular) { type = GetSmartType(from, to, type); t = ApplyLerp(t, type); return(ApplyRounding(Mathf.Lerp(from, to, t), rounding)); }
public static Int32 IntRoundDown(decimal valueDec) { return(IntRounding.RoundDown(valueDec)); }