Advertisement
tomlev

C# tax calculation

Sep 23rd, 2011
2,767
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.62 KB | None | 0 0
  1. decimal GetTaxes(decimal salary)
  2. {
  3.     var rates = new[]
  4.     {
  5.         new { Threshold = 40230.0m, Rate = 0.45m },
  6.         new { Threshold = 21240.0m, Rate = 0.33m },
  7.         new { Threshold = 14070.0m, Rate = 0.3m },
  8.         new { Threshold = 8660.0m, Rate = 0.23m },
  9.         new { Threshold = 5070.0m, Rate = 0.14m },
  10.         new { Threshold = 0.0m, Rate = 0.1m },
  11.     };
  12.    
  13.     decimal tax = 0;
  14.     foreach (var r in rates)
  15.     {
  16.         decimal slice = salary - r.Threshold;
  17.         if (slice <= 0)
  18.             continue;
  19.         tax += r.Rate * slice;
  20.         salary -= slice;
  21.     }
  22.    
  23.     return tax;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement