changeset 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 0e64a120785f
children 6e46a62ad9b8
files CustomMath/IBBMath.cs
diffstat 1 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/CustomMath/IBBMath.cs	Tue Oct 27 19:58:57 2009 +0000
+++ b/CustomMath/IBBMath.cs	Fri Nov 06 19:57:34 2009 +0000
@@ -129,5 +129,23 @@
 		{
 			return (roundUp ? Math.Ceiling(number) : Math.Floor(number));
 		}
+		
+		/// <summary>
+		/// Takes two integers and gets the percentage of the latter that the former represents. If the numerator is less than
+		/// or equal to the denominator then this will be a number between 0.0 and 100.0.
+		/// </summary>
+		/// <param name="numerator">
+		/// The numerator of the percentage (the top number)
+		/// </param>
+		/// <param name="denominator">
+		/// The denominator of the percentage (the bottom number - the divisor)
+		/// </param>
+		/// <returns>
+		/// 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
+		/// </returns>
+		public static double Percentage(int numerator, int denominator)
+		{
+			return (numerator / (double) denominator) * 100;
+		}
 	}
 }