Skip to content

Instantly share code, notes, and snippets.

@DTTerastar
Created December 5, 2012 16:02
Show Gist options
  • Save DTTerastar/4216893 to your computer and use it in GitHub Desktop.
Save DTTerastar/4216893 to your computer and use it in GitHub Desktop.
PercentComplete
public class PercentComplete : IDisposable
{
private readonly float _max;
private readonly float _min;
private readonly int _total;
private int _current;
public PercentComplete(int total)
: this(total, 0, 100)
{
}
private PercentComplete(int total, float min, float max)
{
_total = total;
_min = min;
_max = max;
}
public int IntValue
{
get { return (int)Math.Round(Calc(_current)); }
}
public float Value
{
get { return Calc(_current); }
}
public void Dispose()
{
}
private float Calc(int current)
{
return _min + (current * (_max - _min)) / _total;
}
public void Next()
{
_current++;
}
public PercentComplete Next(int subTotal)
{
return new PercentComplete(subTotal, Calc(_current), Calc(++_current));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment