# HG changeset patch # User IBBoard # Date 1257800298 0 # Node ID 057498981bde3489e8eed247d5ac8c2b7b6463ae # Parent 83c259516041905dd62a648ff47470cdbc651fca Re #209: equipmentslot Value problem * Simple hack to stop the UI erroring - make sure that the value is between min and max Underlying problem still exists in the API as adding 1 as a percentage to a unit of 11 (9.1%) is actually 9.09% recurring, which is 1.001, which is rounded to 2 when calculating cost. Perhaps percentages need to always be rounded down instead of up/down based on equipment properties? diff -r 83c259516041 -r 057498981bde UI/EquipmentAmountControl.cs --- a/UI/EquipmentAmountControl.cs Mon Nov 09 16:33:17 2009 +0000 +++ b/UI/EquipmentAmountControl.cs Mon Nov 09 20:58:18 2009 +0000 @@ -135,7 +135,8 @@ private decimal CalculateNumericValueFromPercentage(decimal percent) { - return (decimal) IBBoard.CustomMath.IBBMath.Round((double)(unit.Size * (percent / 100)), equip.RoundNumberUp); + decimal calcedAmount = (decimal) IBBoard.CustomMath.IBBMath.Round((double)(unit.Size * (percent / 100)), equip.RoundNumberUp); + return Math.Min(Math.Max(calcedAmount, numeric.Minimum), numeric.Maximum); } private void numeric_ValueChanged(object sender, EventArgs e) @@ -154,7 +155,8 @@ private decimal CalcualtePercentageValueFromNumber(int number) { - return (decimal) RoundPercentage((number / (unit.Size * 1.0)) * 100); + decimal calcedAmount = (decimal) RoundPercentage(IBBoard.CustomMath.IBBMath.Percentage(number, unit.Size)); + return Math.Min(Math.Max(calcedAmount, percentage.Minimum), percentage.Maximum); } private double RoundPercentage(double percent)