NumberF.Tax (NumberF v0.1.8)

View Source

Functions 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

calculate_capital_gains_tax(gain, rate, exemption \\ 0)

Calculates tax on capital gains, with optional annual exemption.

Parameters

  • gain: The capital gain amount
  • rate: The capital gains tax rate as a decimal
  • exemption: 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}

calculate_corporate_tax(profit, rate)

Calculates corporate tax on profits.

Parameters

  • profit: The taxable profit
  • rate: 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}

calculate_income_tax(income, brackets)

Calculates progressive income tax based on tax brackets.

Parameters

  • income: The taxable income
  • brackets: 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}

calculate_payroll_tax(salary, employee_rate, employer_rate, cap \\ nil)

Calculates payroll taxes including employee and employer contributions.

Parameters

  • salary: The gross salary
  • employee_rate: The employee contribution rate as a decimal
  • employer_rate: The employer contribution rate as a decimal
  • cap: 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}

calculate_sales_tax(amount, rate, options \\ [])

Calculates sales tax for a given amount and rate.

Parameters

  • amount: The amount before tax
  • rate: 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}

calculate_vat(amount, rate, included \\ false)

Calculates Value Added Tax (VAT) for a given amount and rate.

Parameters

  • amount: The amount before tax
  • rate: 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}

calculate_withholding_tax(amount, rate)

Calculates withholding tax for dividends or interest based on a flat rate.

Parameters

  • amount: The gross amount
  • rate: 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}

income_tax_brackets()

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}]

vat_rates()

Returns common VAT rates for different countries.

Examples

iex> NumberF.Tax.vat_rates()["UK"]
0.2

iex> NumberF.Tax.vat_rates()["Germany"]
0.19