NumberF.Tax (NumberF v0.1.7)
View SourceFunctions for tax calculations including VAT, sales tax, and income tax.
Summary
Functions
Calculates tax on capital gains, with optional annual exemption.
Calculates corporate tax on profits.
Calculates progressive income tax based on tax brackets.
Calculates payroll taxes including employee and employer contributions.
Calculates sales tax for a given amount and rate.
Calculates Value Added Tax (VAT) for a given amount and rate.
Calculates withholding tax for dividends or interest based on a flat rate.
Returns sample income tax brackets for different countries. Note: These are simplified examples and may not reflect current tax law.
Returns common VAT rates for different countries.
Functions
Calculates tax on capital gains, with optional annual exemption.
Parameters
gain
: The capital gain amountrate
: The capital gains tax rate as a decimalexemption
: Annual tax-free allowance (default: 0)
Examples
iex> NumberF.Tax.calculate_capital_gains_tax(20000, 0.2, 12300)
%{gain: 20000.0, taxable_gain: 7700.0, tax: 1540.0, net: 18460.0}
Calculates corporate tax on profits.
Parameters
profit
: The taxable profitrate
: The corporate tax rate as a decimal
Examples
iex> NumberF.Tax.calculate_corporate_tax(100000, 0.19)
%{profit: 100000.0, tax: 19000.0, after_tax: 81000.0}
Calculates progressive income tax based on tax brackets.
Parameters
income
: The taxable incomebrackets
: A list of tax brackets, each as a tuple {threshold, rate}sorted in ascending order by threshold
Examples
iex> brackets = [{0, 0.0}, {12570, 0.2}, {50270, 0.4}, {150000, 0.45}]
iex> NumberF.Tax.calculate_income_tax(30000, brackets)
%{tax: 3486.0, effective_rate: 0.1162}
Calculates payroll taxes including employee and employer contributions.
Parameters
salary
: The gross salaryemployee_rate
: The employee contribution rate as a decimalemployer_rate
: The employer contribution rate as a decimalcap
: Maximum amount subject to payroll tax (default: nil, no cap)
Examples
iex> NumberF.Tax.calculate_payroll_tax(50000, 0.12, 0.138)
%{salary: 50000.0, employee_contribution: 6000.0, employer_contribution: 6900.0, total_cost: 56900.0, take_home: 44000.0}
Calculates sales tax for a given amount and rate.
Parameters
amount
: The amount before taxrate
: The sales tax rate as a decimal (e.g., 0.06 for 6%)options
: Additional options:round_to
: Round the tax amount to the nearest value (default: 0.01)
Examples
iex> NumberF.Tax.calculate_sales_tax(100, 0.06)
%{subtotal: 100.0, tax: 6.0, total: 106.0}
iex> NumberF.Tax.calculate_sales_tax(100, 0.06, round_to: 0.05)
%{subtotal: 100.0, tax: 6.0, total: 106.0}
Calculates Value Added Tax (VAT) for a given amount and rate.
Parameters
amount
: The amount before taxrate
: The VAT rate as a decimal (e.g., 0.2 for 20%)included
: Whether the amount already includes VAT (default: false)
Examples
iex> NumberF.Tax.calculate_vat(100, 0.2)
%{net: 100.0, vat: 20.0, gross: 120.0}
iex> NumberF.Tax.calculate_vat(120, 0.2, true)
%{net: 100.0, vat: 20.0, gross: 120.0}
Calculates withholding tax for dividends or interest based on a flat rate.
Parameters
amount
: The gross amountrate
: The withholding tax rate as a decimal
Examples
iex> NumberF.Tax.calculate_withholding_tax(1000, 0.15)
%{gross: 1000.0, tax: 150.0, net: 850.0}
Returns sample income tax brackets for different countries. Note: These are simplified examples and may not reflect current tax law.
Examples
iex> NumberF.Tax.income_tax_brackets()["US"]
[{0, 0.1}, {9950, 0.12}, {40525, 0.22}, {86375, 0.24}, {164925, 0.32}, {209425, 0.35}, {523600, 0.37}]
Returns common VAT rates for different countries.
Examples
iex> NumberF.Tax.vat_rates()["UK"]
0.2
iex> NumberF.Tax.vat_rates()["Germany"]
0.19