finance.tax.remove-vat
Extract the VAT already included in a gross amount, using the rate in force on the date of supply.
1.0.1 (not the latest) · published 2026-10-03 by charlie · Anterra
Pinned by 20 tests, run in TypeScript, Python and Rust.
Not professional advice. This capability calculates tax figures from published rules. It is a software component for developers, not tax advice. Rules change and every rate here has an effective date. Check that the dates cover your case. Verify results against the official sources listed in its README, and have a chartered accountant or tax adviser review how you use it, before anyone relies on the output. Provided “as is” under its licence, without warranty.
What it does
Retail prices are quoted gross. Taking 20% off a gross price is the classic error: the VAT in a 120.00 gross price is 20.00, not 24.00.
The net is gross x 10000 / (10000 + rate), and the tax is whatever is left, so net and tax always add back to exactly the gross with no stray penny.
For example
remove_vat(£120.00, GB, STANDARD, 2026-09-16)→ net £100.00, tax £20.00, gross £120.00, rate 20% VAT inside 120 pounds is 20, not 24remove_vat(£2.39, GB, STANDARD, 2026-09-16)→ net £1.99, tax £0.40, gross £2.39, rate 20% round trips with add-vatremove_vat(£1.00, GB, STANDARD, 2026-09-16)→ net £0.83, tax £0.17, gross £1.00, rate 20% a 1 pound gross price
The function
The same function in TypeScript, Python and Rust, pinned by the same tests. Pick your language; the choice follows you around the registry.
pub fn remove_vat(gross: &Money, jurisdiction: &str, category: &str, on_date: &str) -> VatBreakdown
| gross | Money | the VAT-inclusive amount |
| jurisdiction | string | |
| category | string | |
| on_date | date | date of supply, not today |
| returns | VatBreakdown |
Your code names it in one line, in the file that uses it
fune!(finance.tax.remove-vat@^1); // then call remove_vat(…)
Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.
use super::funejson::Value; ← the fune runtime: the JSON value the test vectors use; fune build keeps it only where a signature takes one
use super::finance_tax_add_vat::{vat_breakdown_to_value, VatBreakdown}; ← from finance.tax.add-vat ^1.0.0 · built alongside by fune
use super::finance_tax_vat_rate::vat_rate; ← from finance.tax.vat-rate ^1.0.0 · built alongside by fune
use super::math_round_div::round_div; ← from math.round-div ^1.0.0 · built alongside by fune
use super::money_amount::{money, money_from_value, Money}; ← from money.amount ^1.0.0 · built alongside by fune
/// Extract the VAT already included in a gross amount.
///
/// Taking 20% off a gross price is the classic error: the VAT inside a 120.00
/// gross price is 20.00, not 24.00. The net is gross x 10000 / (10000 + rate),
/// and the tax is the remainder, so the parts always add back to exactly the
/// gross with no stray penny.
pub fn remove_vat(
gross: &Money,
jurisdiction: &str,
category: &str,
on_date: &str,
) -> VatBreakdown {
let rate = vat_rate(jurisdiction, category, on_date);
let net = money(
round_div(gross.minor * 10000, 10000 + rate.basis_points, "half-up"),
&gross.currency,
);
VatBreakdown {
tax: money(gross.minor - net.minor, &gross.currency),
net,
gross: gross.clone(),
basis_points: rate.basis_points,
}
}
pub fn fune_vector(args: &[Value]) -> Value {
vat_breakdown_to_value(&remove_vat(
&money_from_value(&args[0]),
args[1].as_str(),
args[2].as_str(),
args[3].as_str(),
))
}Install
fune build
With that line in your source, in a Rust project (language rust in fune.project), fune build resolves it and its 4 dependencies, pins them in fune.lock, downloads only the Rust package of each, and builds the code above into your project’s .fune/build, one readable file per capability with a header linking back here. A crate’s build.rs runs it before every compile. Or pin a range in fune.project and build in one step:
fune add finance.tax.remove-vat
The manifest, vectors and README with only the Rust implementation. Install it without the registry with fune add ./finance.tax.remove-vat-1.0.1-rust.fune, or fetch it from a terminal with fune pull finance.tax.remove-vat@1.0.1:rust.
The whole function, every language, is one file too: finance.tax.remove-vat-1.0.1.fune, 11,587 bytes, sha256 bbad1ea5f661fe68687fe1b6b6857904e8dd7422f9aa7d4501a896ac893b51d2. It installs into a project of any language.
Customise it in your app
The seams this capability offers. Put a marker directly above a function of your own and fune build wires it into the built code; the package on the registry is not changed, the built file’s header lists it under CUSTOMISED, and fune hooks lists every hook in the project. How hooks work.
before — your function gets the arguments and returns them, changed or not, or throws to refuse the call.
// fune: before finance.tax.remove-vat
after — your function gets the result and the arguments, and returns the final result.
// fune: after finance.tax.remove-vat
replace — inside this capability’s code only, calls to a dependency go to your function, with the same signature. Other capabilities that use it are unaffected; write in * to replace it everywhere.
// fune: replace finance.tax.add-vat in finance.tax.remove-vat
// fune: replace finance.tax.vat-rate in finance.tax.remove-vat
// fune: replace math.round-div in finance.tax.remove-vat
// fune: replace money.amount in finance.tax.remove-vat
step — your function runs at a numbered point inside the function’s body, receives the in-scope values it names as parameters, and may return replacements. List the points with fune show finance.tax.remove-vat --steps.
// fune: step finance.tax.remove-vat after <n|label>
Tests
A version published now needs at least 8 tests for every function, and one that expects the error for each function that throws; the registry refuses it otherwise. fune verify --all runs each case in TypeScript, Python and Rust, and a project runs them again with fune verify. This page lists the cases; it does not run them. The exact JSON is vectors.json.
| Case | Arguments | Expected | |
|---|---|---|---|
| VAT inside 120 pounds is 20, not 24 | £120.00, GB, STANDARD, 2026-09-16 | → | net £100.00, tax £20.00, gross £120.00, rate 20% |
| round trips with add-vat | £2.39, GB, STANDARD, 2026-09-16 | → | net £1.99, tax £0.40, gross £2.39, rate 20% |
| a 1 pound gross price | £1.00, GB, STANDARD, 2026-09-16 | → | net £0.83, tax £0.17, gross £1.00, rate 20% |
| zero rated gross is all net | £100.00, GB, ZERO, 2026-09-16 | → | net £100.00, tax £0.00, gross £100.00, rate 0% |
| reduced rate gross | £105.00, GB, REDUCED, 2026-09-16 | → | net £100.00, tax £5.00, gross £105.00, rate 5% |
| a 2009 gross price uses the 2009 rate | £115.00, GB, STANDARD, 2009-06-01 | → | net £100.00, tax £15.00, gross £115.00, rate 15% |
| a refund of a gross price | -£120.00, GB, STANDARD, 2026-09-16 | → | net -£100.00, tax -£20.00, gross -£120.00, rate 20% |
| a tie in the net rounds half up, so 9p holds 1p of VAT, not the 2p that 20% of the net suggests | £0.09, GB, STANDARD, 2026-09-16 | → | net £0.08, tax £0.01, gross £0.09, rate 20% |
| a refund's tie rounds away from zero the same way | -£0.09, GB, STANDARD, 2026-09-16 | → | net -£0.08, tax -£0.01, gross -£0.09, rate 20% |
| a penny holds no VAT | £0.01, GB, STANDARD, 2026-09-16 | → | net £0.01, tax £0.00, gross £0.01, rate 20% |
Show the other 10 tests
| Case | Arguments | Expected | |
|---|---|---|---|
| zero gross is zero everything | £0.00, GB, STANDARD, 2026-09-16 | → | net £0.00, tax £0.00, gross £0.00, rate 20% |
| exempt supplies carry no VAT | £100.00, GB, EXEMPT, 2026-09-16 | → | net £100.00, tax £0.00, gross £100.00, rate 0% |
| a 2010 gross price uses the 17.5% rate | £117.50, GB, STANDARD, 2010-06-01 | → | net £100.00, tax £17.50, gross £117.50, rate 17.5% |
| an Irish gross price uses the Irish 23% rate | €123.00, IE, STANDARD, 2026-09-16 | → | net €100.00, tax €23.00, gross €123.00, rate 23% |
| an Irish reduced rate that does not divide evenly | €10.00, IE, REDUCED, 2026-09-16 | → | net €8.81, tax €1.19, gross €10.00, rate 13.5% |
| a large gross stays exact | £1,200,000,000.00, GB, STANDARD, 2026-09-16 | → | net £1,000,000,000.00, tax £200,000,000.00, gross £1,200,000,000.00, rate 20% |
| a jurisdiction with no rules is an error | £120.00, XX, STANDARD, 2026-09-16 | → | error: no VAT rule |
| a category with no rules is an error | £120.00, GB, LUXURY, 2026-09-16 | → | error: no VAT rule |
| a date that is not ISO is an error | £120.00, GB, STANDARD, 16/09/2026 | → | error: ISO date |
| an invalid currency is an error | 120.00 gbp, GB, STANDARD, 2026-09-16 | → | error: ISO 4217 |
More from the author
1.0.1 adds tests; behaviour unchanged.
Files
| Path | Bytes |
|---|---|
| README.md | 352 |
| impl/python.py | 922 |
| impl/rust.rs | 1,263 |
| impl/typescript.ts | 952 |
| vectors.json | 5,516 |