changeset 31:7a3749a2d8e6

Re #19 - Add "Round to half" method * Create IBBMath class and add static "RoundToHalf" method for doubles
author IBBoard <dev@ibboard.co.uk>
date Sun, 17 May 2009 16:09:22 +0000
parents 23fd4247fc1c
children 267cd5ce66ff
files IBBoard.csproj Lang/IBBMath.cs
diffstat 2 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/IBBoard.csproj	Sun Apr 19 11:31:47 2009 +0000
+++ b/IBBoard.csproj	Sun May 17 16:09:22 2009 +0000
@@ -125,6 +125,7 @@
     <Compile Include="Lang\TranslationLoadException.cs" />
     <Compile Include="Xml\XmlTools.cs" />
     <Compile Include="IO\BinaryReaderBigEndian.cs" />
+    <Compile Include="Lang\IBBMath.cs" />
   </ItemGroup>
   <ItemGroup>
     <Content Include="libs\log4net.dll" />
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Lang/IBBMath.cs	Sun May 17 16:09:22 2009 +0000
@@ -0,0 +1,27 @@
+//  This file (IBBMath.cs) is a part of the IBBoard project and is copyright 2009 IBBoard
+// 
+//  The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.
+// 
+
+using System;
+
+namespace IBBoard.Lang
+{
+	public class IBBMath
+	{
+		/// <summary>
+		/// Rounds a number to the closest half, with a bias towards whole numbers. This is equivalent to 'round-to-even' in that
+		/// 0.25 is rounded down to 0.0 and 0.75 is rounded up to 1.0 so that a bias isn't introduced by rounding.
+		/// </summary>
+		/// <param name="number">
+		/// The <see cref="System.Double"/> to round to the nearest 0.5
+		/// </param>
+		/// <returns>
+		/// <code>param</code> rounded to the nearest 0.5
+		/// </returns>
+		public static double RoundToHalf(double number)
+		{
+			return Math.Round(number * 2) / 2;
+		}
+	}
+}