Functional Weave
Code in TypeScript

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.0 (not the latest) · published 2026-10-03 by charlie · Anterra

Pinned by 7 tests, run in TypeScript, Python and Rust · fewer than the registry now requires. 1.0.2 adds them.

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

  • removeVat(£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 24
  • removeVat(£2.39, GB, STANDARD, 2026-09-16) → net £1.99, tax £0.40, gross £2.39, rate 20% round trips with add-vat
  • removeVat(£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.

export function removeVat(gross: Money, jurisdiction: string, category: string, onDate: string): VatBreakdown
grossMoneythe VAT-inclusive amount
jurisdictionstring
categorystring
onDatedatedate of supply, not today
returnsVatBreakdown

Your code names it in one line, in the file that uses it

import { removeVat } from "#fune/finance.tax.remove-vat@^1";
impl/typescript.ts · 23 lines · open · raw

Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.

import { type VatBreakdown } from "./finance_tax_add_vat.ts";  ← from finance.tax.add-vat ^1.0.0 · built alongside by fune
import { vatRate } from "./finance_tax_vat_rate.ts";  ← from finance.tax.vat-rate ^1.0.0 · built alongside by fune
import { roundDiv } from "./math_round_div.ts";  ← from math.round-div ^1.0.0 · built alongside by fune
import { type Money, money } from "./money_amount.ts";  ← 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.
 */
export function removeVat(gross: Money, jurisdiction: string, category: string, onDate: string): VatBreakdown {
  const rate = vatRate(jurisdiction, category, onDate);
  const net = money(roundDiv(gross.minor * 10000, 10000 + rate.basisPoints, "half-up"), gross.currency);
  return {
    net,
    tax: money(gross.minor - net.minor, gross.currency),
    gross,
    basisPoints: rate.basisPoints,
  };
}

Install

fune build

With that line in your source, in a TypeScript project (language typescript in fune.project), fune build resolves it and its 4 dependencies, pins them in fune.lock, downloads only the TypeScript 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. Or pin a range in fune.project and build in one step:

fune add finance.tax.remove-vat
Download for TypeScript finance.tax.remove-vat-1.0.0-typescript.fune · 5,311 bytes sha256 a448442112bff9a377e4db17d59abf187159f9c51af0566baaee9fbdc97cdf0b

The manifest, vectors and README with only the TypeScript implementation. Install it without the registry with fune add ./finance.tax.remove-vat-1.0.0-typescript.fune, or fetch it from a terminal with fune pull finance.tax.remove-vat@1.0.0:typescript.

The whole function, every language, is one file too: finance.tax.remove-vat-1.0.0.fune, 7,589 bytes, sha256 3da67ed18e1dd6d2f1ea8edc804bc28d11b536bac10981509f6f8f9440fb68ea. 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.

This version has fewer tests than the registry now requires. It was published before every function had to have 8. 1.0.2 meets it, and a project on ^1.0.0 installs that or newer.

  • removeVat has 7 tests; every function needs at least 8. Add 1 more to vectors.json: the ordinary case, the boundaries (zero, negative, the largest values), the rounding edge and every error it documents
  • removeVat throws (throws yes) but none of its 7 tests expects an error; add an "expectError" vector for each error it documents, or declare `throws no` if it cannot throw
CaseArgumentsExpected
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%

Files

PathBytes
README.md312
impl/python.py922
impl/rust.rs1,263
impl/typescript.ts952
vectors.json2,075