# HG changeset patch # User IBBoard # Date 1257192678 0 # Node ID 971f7801f98485425706b37c6dee90a61be78c29 # Parent 340e711ca4c3694c4d7b33929163c7d68c551cb4 Fixes #205: Odd/prime numbers causes a crash * Fix crash with number out of range by rounding our min/max percentage the same as we round the calculated value diff -r 340e711ca4c3 -r 971f7801f984 UI/EquipmentAmountControl.cs --- a/UI/EquipmentAmountControl.cs Mon Nov 02 20:02:12 2009 +0000 +++ b/UI/EquipmentAmountControl.cs Mon Nov 02 20:11:18 2009 +0000 @@ -49,9 +49,9 @@ { if (equip != null) { - bool equipIsRatioLimit = UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip); - double maxPercent = UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip); - double minPercent = UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip); + bool equipIsRatioLimit = UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip); + double maxPercent = RoundPercentage(UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); + double minPercent = RoundPercentage(UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); int maxNumber = UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip); int minNumber = UnitEquipmentUtil.GetMinEquipmentCount(unit, equip); @@ -151,8 +151,13 @@ } private decimal CalcualtePercentageValueFromNumber(int number) - { - return (decimal) Math.Round((number / (unit.Size * 1.0)) * 100, 1); + { + return (decimal) RoundPercentage((number / (unit.Size * 1.0)) * 100); + } + + private double RoundPercentage(double percent) + { + return Math.Round(percent, 1); } public double EquipmentAmount