Skip to content

Instantly share code, notes, and snippets.

@hahmed
Forked from flq/tax.cs
Created September 22, 2011 12:02
Show Gist options
  • Save hahmed/1234625 to your computer and use it in GitHub Desktop.
Save hahmed/1234625 to your computer and use it in GitHub Desktop.
the tax thingy
public decimal GetTaxes(decimal salary)
{
decimal tax = 0;
var progressiveTaxation = new[] { 0.1m, 0.14m, 0.23m, 0.3m, 0.33m, 0.45m };
var progressionSlices = new[] { 5070 - 0, 8660 - 5070, 14070 - 8660, 21240 - 14070, 40230 - 21240, decimal.MaxValue };
var progression = 0;
while (salary > 0)
{
var taxedSlice = salary - progressionSlices[progression] > 0 ? progressionSlices[progression] : salary;
tax += taxedSlice * progressiveTaxation[progression];
salary -= taxedSlice;
progression++;
}
return tax;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment