comparison CustomMath/IBBMath.cs @ 61:972cc51adeeb

* Add method for making percentage of one integer compared to another to ensure consistency no-open-ticket
author IBBoard <dev@ibboard.co.uk>
date Fri, 06 Nov 2009 19:57:34 +0000
parents 298b2ff956bb
children
comparison
equal deleted inserted replaced
60:0e64a120785f 61:972cc51adeeb
127 /// </returns> 127 /// </returns>
128 public static double Round(double number, bool roundUp) 128 public static double Round(double number, bool roundUp)
129 { 129 {
130 return (roundUp ? Math.Ceiling(number) : Math.Floor(number)); 130 return (roundUp ? Math.Ceiling(number) : Math.Floor(number));
131 } 131 }
132
133 /// <summary>
134 /// Takes two integers and gets the percentage of the latter that the former represents. If the numerator is less than
135 /// or equal to the denominator then this will be a number between 0.0 and 100.0.
136 /// </summary>
137 /// <param name="numerator">
138 /// The numerator of the percentage (the top number)
139 /// </param>
140 /// <param name="denominator">
141 /// The denominator of the percentage (the bottom number - the divisor)
142 /// </param>
143 /// <returns>
144 /// The percentage, where 100% is the double value 100.0, or positive/negative infinity where numerator is non-zero and denominator is zero, or NaN where numerator and denominator are zero
145 /// </returns>
146 public static double Percentage(int numerator, int denominator)
147 {
148 return (numerator / (double) denominator) * 100;
149 }
132 } 150 }
133 } 151 }