Mercurial > repos > IBBoard.WarFoundry.GUI.WinForms
changeset 89:971f7801f984
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
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 02 Nov 2009 20:11:18 +0000 |
parents | 340e711ca4c3 |
children | 63ca28bd8ada |
files | UI/EquipmentAmountControl.cs |
diffstat | 1 files changed, 10 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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