annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
46
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // This file (IBBMath.cs) is a part of the IBBoard project and is copyright 2009 IBBoard
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 // 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.
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 //
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using System;
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 namespace IBBoard.CustomMath
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 {
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 /// <summary>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 /// RoundType defines how a number should be rounded. "Up" always rounds up (Ceiling), "Down" always rounds down (Floor), "Banker" rounds
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 /// up or down as appropriate with a balanced bias (rounding towards even). Each rounding method also has a "ToHalf" version that performs
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 /// the same type of rounding, but to the closes half number instead of the closest whole number.
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 /// </summary>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 public enum RoundType
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 {
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 Up,
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 Down,
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 Banker,
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 UpToHalf,
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 DownToHalf,
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 BankerToHalf
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 }
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 /// <summary>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 /// IBBMath provides a number of custom Maths functions based on the core Math classes.
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 /// </summary>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 public class IBBMath
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 {
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 /// <summary>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 /// Rounds a number to the closest half, with a bias towards whole numbers. This is equivalent to 'round-to-even' in that
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 /// 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.
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 /// </summary>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 /// <param name="number">
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 /// The <see cref="System.Double"/> to round to the nearest 0.5
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 /// </param>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 /// <returns>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38 /// <code>param</code> rounded to the nearest 0.5
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 /// </returns>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 public static double RoundToHalf(double number)
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 {
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 return Math.Round(number * 2) / 2;
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 }
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 /// <summary>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 /// Returns the largest whole or half number that is less than or equal to the specified number.
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 /// </summary>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 /// <param name="number">
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 /// The <see cref="System.Double"/> to round to the nearest 0.5
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 /// </param>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51 /// <returns>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52 /// <code>param</code> rounded to the nearest 0.5 that is less than or equal to <code>param</code>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53 /// </returns>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54 public static double FloorToHalf(double number)
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55 {
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 return Math.Floor(number * 2) / 2;
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 }
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59 /// <summary>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60 /// Returns the smallest whole or half number that is greater than or equal to the specified number.
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61 /// </summary>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
62 /// <param name="number">
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63 /// The <see cref="System.Double"/> to round to the nearest 0.5
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64 /// </param>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 /// <returns>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66 /// <code>param</code> rounded to the nearest 0.5 that is greater than or equal to <code>param</code>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
67 /// </returns>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68 public static double CeilToHalf(double number)
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
69 {
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
70 return Math.Ceiling(number * 2) / 2;
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
71 }
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
72
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
73 /// <summary>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74 /// Returns the number rounded as defined by the <code>roundType</code>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
75 /// </summary>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
76 /// <param name="number">
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
77 /// The <see cref="System.Double"/> to round
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
78 /// </param>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
79 /// <param name="roundType">
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
80 /// The way in which <code>number</code> should be rounded
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
81 /// </param>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
82 /// <returns>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
83 /// The rounded <see cref="System.Double"/>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
84 /// </returns>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
85 public static double Round(double number, RoundType roundType)
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
86 {
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
87 double val;
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
88
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
89 switch (roundType)
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
90 {
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
91 case RoundType.Up:
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
92 val = Math.Ceiling(number);
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
93 break;
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
94 case RoundType.Down:
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
95 val = Math.Floor(number);
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
96 break;
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
97 case RoundType.Banker:
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
98 val = Math.Round(number);
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
99 break;
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
100 case RoundType.UpToHalf:
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
101 val = CeilToHalf(number);
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
102 break;
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
103 case RoundType.DownToHalf:
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
104 val = FloorToHalf(number);
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
105 break;
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
106 case RoundType.BankerToHalf:
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
107 val = RoundToHalf(number);
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
108 break;
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
109 default:
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
110 throw new InvalidOperationException("Unhandled round type: "+roundType);
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
111 }
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
112
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
113 return val;
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
114 }
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
115
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
116 /// <summary>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
117 /// Returns the number rounded up or down to the closest whole number.
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
118 /// </summary>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
119 /// <param name="number">
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
120 /// The <see cref="System.Double"/> to round
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
121 /// </param>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
122 /// <param name="roundUp">
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
123 /// <code>true</code> to round up, else rounds down
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
124 /// </param>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
125 /// <returns>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
126 /// The rounded <see cref="System.Double"/>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
127 /// </returns>
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
128 public static double Round(double number, bool roundUp)
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
129 {
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
130 return (roundUp ? Math.Ceiling(number) : Math.Floor(number));
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
131 }
61
972cc51adeeb * Add method for making percentage of one integer compared to another to ensure consistency
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
132
972cc51adeeb * Add method for making percentage of one integer compared to another to ensure consistency
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
133 /// <summary>
972cc51adeeb * Add method for making percentage of one integer compared to another to ensure consistency
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
134 /// Takes two integers and gets the percentage of the latter that the former represents. If the numerator is less than
972cc51adeeb * Add method for making percentage of one integer compared to another to ensure consistency
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
135 /// or equal to the denominator then this will be a number between 0.0 and 100.0.
972cc51adeeb * Add method for making percentage of one integer compared to another to ensure consistency
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
136 /// </summary>
972cc51adeeb * Add method for making percentage of one integer compared to another to ensure consistency
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
137 /// <param name="numerator">
972cc51adeeb * Add method for making percentage of one integer compared to another to ensure consistency
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
138 /// The numerator of the percentage (the top number)
972cc51adeeb * Add method for making percentage of one integer compared to another to ensure consistency
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
139 /// </param>
972cc51adeeb * Add method for making percentage of one integer compared to another to ensure consistency
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
140 /// <param name="denominator">
972cc51adeeb * Add method for making percentage of one integer compared to another to ensure consistency
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
141 /// The denominator of the percentage (the bottom number - the divisor)
972cc51adeeb * Add method for making percentage of one integer compared to another to ensure consistency
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
142 /// </param>
972cc51adeeb * Add method for making percentage of one integer compared to another to ensure consistency
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
143 /// <returns>
972cc51adeeb * Add method for making percentage of one integer compared to another to ensure consistency
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
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
972cc51adeeb * Add method for making percentage of one integer compared to another to ensure consistency
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
145 /// </returns>
972cc51adeeb * Add method for making percentage of one integer compared to another to ensure consistency
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
146 public static double Percentage(int numerator, int denominator)
972cc51adeeb * Add method for making percentage of one integer compared to another to ensure consistency
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
147 {
972cc51adeeb * Add method for making percentage of one integer compared to another to ensure consistency
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
148 return (numerator / (double) denominator) * 100;
972cc51adeeb * Add method for making percentage of one integer compared to another to ensure consistency
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
149 }
46
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
150 }
298b2ff956bb * Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
151 }