Created
November 23, 2015 23:24
-
-
Save liath/f4c65891ad90f71ddf30 to your computer and use it in GitHub Desktop.
US Federal Income Tax calculator in javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 : { // Single | |
0 : { p : 0, s : 0 }, | |
44 : { p: 0.1, s: 0 }, | |
222 : { p: 0.15, s: 17.8 }, | |
764 : { p: 0.25, s: 99.1 }, | |
1789 : { p: 0.28, s: 355.35 }, | |
3685 : { p: 0.33, s: 886.23 }, | |
7958 : { p: 0.35, s: 2296.32 }, | |
7990 : { p: 0.396, s: 2307.52 } | |
}, | |
m : { // Married | |
0 : { p : 0, s : 0 }, | |
165 : { p : 0.1, s : 0 }, | |
520 : { p : 0.15, s : 35.5 }, | |
1606 : { p : 0.25, s : 198.4 }, | |
3073 : { p : 0.28, s : 565.15 }, | |
4597 : { p : 0.33, s : 991.87 }, | |
8079 : { p : 0.35, s : 2140.93 }, | |
9105 : { p : 0.396, s : 2500.03 } | |
} | |
}, | |
ba = 76.9, // 1 Allowance | |
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 | |
} | |
} | |
} |
So, if you're single with one allowance and you make $1000 a week you would run c(0, 1, 1000)
. 0 for single, 1 is the allowances, and $1000/week. Should result in 138.875
.
Thank you for this, Liath! I have websites that rely on this code, so I forked it to keep it updated each year: https://gist.github.com/axcviii/502ef703ec727507e5cb1a5232df7fc7 (currently 2018 rates).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm so confused on this one I can't get it to work for the life of me can someone please Help