Reputation: 585
I have this code that calculate dues based on Income value at a specified rate. as below:
public decimal Income { get; set; }
public decimal Rate { get; set; }
public string Dues
{
get
{
return string.Format("{0}", Math.Round((this.Income * (1 /this.Rate) * 0.01m), 2));
}
}
What I want to do is check if the Dues calculation is less than 5.00 then it should set the Dues value to 5.00. I am not sure if this can be done.
Any help will be appreciated.
Upvotes: 1
Views: 3035
Reputation: 32099
Write as follows:
public class Foo
{
public decimal Income { get; set; }
public decimal Rate { get; set; }
public decimal Dues
{
get
{
decimal totalDues = Math.Round((this.Income * (1 / this.Rate) * 0.01m), 2);
return totalDues >= 5.00M ? totalDues : 5.00M;
}
}
}
Upvotes: 3