main
 1using System;
 2using System.Globalization;
 3
 4namespace jive
 5{
 6  public class Percent
 7  {
 8    readonly decimal percentage;
 9
10    public Percent(decimal percentage)
11    {
12      this.percentage = percentage;
13    }
14
15    public Percent(decimal portion_of_total, decimal total)
16    {
17      percentage = portion_of_total/total;
18      percentage *= 100;
19      percentage = Math.Round(percentage, 1);
20    }
21
22    public bool represents(Percent other_percent)
23    {
24      return Equals(other_percent);
25    }
26
27    public bool is_less_than(Percent other_percent)
28    {
29      return percentage.CompareTo(other_percent.percentage) < 0;
30    }
31
32    public static implicit operator Percent(decimal percentage)
33    {
34      return new Percent(percentage);
35    }
36
37    public bool Equals(Percent other)
38    {
39      if (ReferenceEquals(null, other)) return false;
40      if (ReferenceEquals(this, other)) return true;
41      return other.percentage == percentage;
42    }
43
44    public override bool Equals(object obj)
45    {
46      if (ReferenceEquals(null, obj)) return false;
47      if (ReferenceEquals(this, obj)) return true;
48      if (obj.GetType() != typeof (Percent)) return false;
49      return Equals((Percent) obj);
50    }
51
52    public override int GetHashCode()
53    {
54      return percentage.GetHashCode();
55    }
56
57    public override string ToString()
58    {
59      return percentage.ToString(CultureInfo.InvariantCulture);
60    }
61  }
62}