SHARE
TWEET

C# tax calculation

tomlev Sep 23rd, 2011 2,370 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top