changeset 96:057498981bde

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?
author IBBoard <dev@ibboard.co.uk>
date Mon, 09 Nov 2009 20:58:18 +0000
parents 83c259516041
children e356134d73c4
files UI/EquipmentAmountControl.cs
diffstat 1 files changed, 4 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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)