Mercurial > repos > IBBoard
annotate Limits/SimpleRoundedPercentageLimit.cs @ 48:f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
* Add simple rounded limit
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 06 Oct 2009 18:59:25 +0000 |
parents | |
children | a177a3750acd |
rev | line source |
---|---|
48
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
1 // This file (SimpleRoundedPercentageLimit.cs) is a part of the IBBoard project and is copyright 2009 IBBoard |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
2 // |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
4 |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 using System; |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
6 using IBBoard.CustomMath; |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
7 |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
8 namespace IBBoard |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
9 { |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
10 /// <summary> |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
11 /// A percentage-based limit that always either rounds up or down to the closest integer |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
12 /// </summary> |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
13 public class SimpleRoundedPercentageLimit |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
14 { |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
15 private double limit; |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
16 private bool roundUp; |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
17 |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
18 public SimpleRoundedPercentageLimit (double percentageLimit, bool roundFractionUp) |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
19 { |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
20 limit = percentageLimit; |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
21 roundUp = roundFractionUp; |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
22 } |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
23 |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
24 /// <summary> |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
25 /// Gets the limited number, based on the percentage limit that this <code>Limit</code> represents and the rounding direction |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
26 /// </summary> |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
27 /// <param name="size"> |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
28 /// The maximum size |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
29 /// </param> |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
30 /// <returns> |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
31 /// <code>size</code> or the numeric limit this object was created with, whichever is smaller. |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
32 /// </returns> |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
33 public int GetLimit(int size) |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
34 { |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
35 return (int)IBBMath.Round(size * limit / 100, roundUp); |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
36 } |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
37 } |
f3bb5b77a7e4
Re #24: Add "limit" objects that can be used for numeric limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
38 } |