Skip to content

Instantly share code, notes, and snippets.

@i3o
Forked from liath/fedtax.js
Last active April 24, 2019 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save i3o/502ef703ec727507e5cb1a5232df7fc7 to your computer and use it in GitHub Desktop.
Save i3o/502ef703ec727507e5cb1a5232df7fc7 to your computer and use it in GitHub Desktop.
US Federal Income Tax calculator in javascript
// Weekly Employee Income Withholding Calculator by GitHub#Liath
// Based on IRS Circular E - http://www.irs.gov/pub/irs-pdf/p15.pdf
// Per the "Percentage Method"
var w = {
s : {
0 : { p : 0, s : 0 },
71 : { p: 0.10, s: 0 },
254 : { p: 0.12, s: 18.3 },
815 : { p: 0.22, s: 85.62 },
1658 : { p: 0.24, s: 271.08 },
3100 : { p: 0.32, s: 617.16 },
3917 : { p: 0.35, s: 878.6 },
9687 : { p: 0.37, s: 2898.1 }
},
m : { // Married
0 : { p : 0, s : 0 },
222 : { p : 0.1, s : 0 },
588 : { p : 0.12, s : 36.6 },
1711 : { p : 0.22, s : 171.36 },
3395 : { p : 0.24, s : 541.84 },
6280 : { p : 0.32, s : 1234.24 },
7914 : { p : 0.35, s : 1757.12 },
11761 : { p : 0.37, s : 3103.57 }
}
},
ba = 79.8,
c = function(m, a, g) { // Returns Federal Income Tax amount (Married, Allowances, Gross Income)
g -= (ba*a); // Pay after allowances
var b = Object.keys(w[(m==1) ? 'm' : 's']); //Married?
for (var i = 0; i < b.length; i++) { // Find bracket
if (b[i] > g) {
g -= b[i-1]; // Get taxable income
b = w[(m==1) ? 'm' : 's'][b[i-1]]; // Set bracket
return ((b.p*(g)) + b.s); // Taxable income * Tax Rate + Base Tax, per IRS Circular E table 5
}
}
}
@ianrockefeller
Copy link

ianrockefeller commented Nov 15, 2018

typo, line 9: 7815 to 815
Thanks for the code and the update to it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment