<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: daniel wang</title>
    <description>The latest articles on DEV Community by daniel wang (@daniel_wang_718ea181919c8).</description>
    <link>https://dev.to/daniel_wang_718ea181919c8</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4265862%2Fa1340c94-02be-4f7f-85fa-6c509109137f.png</url>
      <title>DEV Community: daniel wang</title>
      <link>https://dev.to/daniel_wang_718ea181919c8</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/daniel_wang_718ea181919c8"/>
    <language>en</language>
    <item>
      <title>Modelling EU VAT across 7 countries in a static site (no backend, no library)</title>
      <dc:creator>daniel wang</dc:creator>
      <pubDate>Fri, 27 Nov 2026 03:17:30 +0000</pubDate>
      <link>https://dev.to/daniel_wang_718ea181919c8/modelling-eu-vat-across-7-countries-in-a-static-site-no-backend-no-library-51gj</link>
      <guid>https://dev.to/daniel_wang_718ea181919c8/modelling-eu-vat-across-7-countries-in-a-static-site-no-backend-no-library-51gj</guid>
      <description>&lt;p&gt;A seller in Germany lists an item at €24.99. A seller in Poland lists the same item at 24.99 zł-equivalent. Both see the same headline number. Neither receives it.&lt;/p&gt;

&lt;p&gt;In the EU, prices are quoted &lt;strong&gt;VAT-inclusive&lt;/strong&gt;. The tax is collected on behalf of the state, and it comes out of the headline price before any platform takes its percentage. That single fact breaks most fee calculators, because they compute percentages against the number on the price tag.&lt;/p&gt;

&lt;p&gt;This is a note on the model, the arithmetic, and one implementation detail I found more interesting than expected: getting the same calculation to run on the server and in the browser without duplicating it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The part everyone gets wrong
&lt;/h2&gt;

&lt;p&gt;Take a €24.99 item at Germany's 19% rate, with a 9% referral fee, 10% creator commission, and 1.5% + €0.25 payment fees.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The intuitive (wrong) calculation:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fees  = 24.99 × (0.09 + 0.10 + 0.015) + 0.25 = 5.37
payout = 24.99 − 5.37 − 7.80 (product) − 3.90 (shipping) = 7.92
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The correct one:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;net price = 24.99 ÷ 1.19                    = 21.00
VAT       = 24.99 − 21.00                   = 3.99   ← never yours
fees      = 21.00 × (0.09 + 0.10 + 0.015) + 0.25 = 4.56
payout    = 21.00 − 4.56 − 7.80 − 3.90      = 4.74
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The gap is €3.17 per order: the intuitive result is &lt;strong&gt;67% higher&lt;/strong&gt; than the real one, and it is entirely an artefact of applying percentages to a base that includes tax.&lt;/p&gt;

&lt;p&gt;At a 20% rate, every percentage is applied to a base that is a fifth larger than the real one. On 500 orders a month a €3 error per order is roughly €1,500 of margin that never existed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Seven rates, one formula
&lt;/h2&gt;

&lt;p&gt;The formula is the same everywhere; only the rate changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;net price     = gross ÷ (1 + rate)
VAT collected = gross − net price
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What changes per country is the rate, and it is not uniform:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Country&lt;/th&gt;
&lt;th&gt;Standard rate&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Germany&lt;/td&gt;
&lt;td&gt;19%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;France&lt;/td&gt;
&lt;td&gt;20%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Netherlands&lt;/td&gt;
&lt;td&gt;21%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Spain&lt;/td&gt;
&lt;td&gt;21%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Italy&lt;/td&gt;
&lt;td&gt;22%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Poland&lt;/td&gt;
&lt;td&gt;23%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sweden&lt;/td&gt;
&lt;td&gt;25%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;That is a 6-point spread. A seller shipping the same product from a Polish warehouse to German and Swedish customers is operating two different margin structures, and the difference is bigger than most shipping-cost variations.&lt;/p&gt;

&lt;p&gt;Under EU distance-selling rules the rate follows the &lt;strong&gt;destination&lt;/strong&gt;, not the warehouse. Which is why the calculator asks for a country rather than a warehouse location.&lt;/p&gt;

&lt;h2&gt;
  
  
  The code: one function, two runtimes
&lt;/h2&gt;

&lt;p&gt;The calculator is a static site. There is no server doing arithmetic at request time — but the first paint still needs real numbers, because a calculator showing &lt;code&gt;—&lt;/code&gt; until JavaScript loads is a bad calculator.&lt;/p&gt;

&lt;p&gt;The trick is that the maths lives in a plain ES module that both runtimes import:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// src/lib/calc.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fallback&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isFinite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;fallback&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;compute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s2"&gt;"tiktok-shop-fee-calculator-eu"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;gross&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;num&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"price"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;netPrice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;gross&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;num&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"vat"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;referral&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;netPrice&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;num&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"referral"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;affiliate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;netPrice&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;num&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"affiliate"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;payment&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;netPrice&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;num&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"feePct"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;num&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"feeFixed"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;takeHome&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;netPrice&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;referral&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;affiliate&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;payment&lt;/span&gt;
                     &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nf"&gt;num&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"cogs"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nf"&gt;num&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"ship"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;takeHome&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;netPrice&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;vatAmount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;gross&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;netPrice&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;netPrice&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;takeHome&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;netPrice&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;fees&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;referral&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;affiliate&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;payment&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="c1"&gt;// …eight other calculators&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The page component imports it twice, for two different consumers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;---
// Build time: render the initial values into the HTML
import { compute, fmt } from "../lib/calc.js";
const out = compute(tool.slug, defaultValues);
const currency = tool.currency ?? "$";
---

&amp;lt;b data-out="takeHome"&amp;gt;{fmt(out.takeHome, "money", currency)}&amp;lt;/b&amp;gt;

&amp;lt;script&amp;gt;
  // Browser: re-run the same function on every input change
  import { compute, fmt } from "../lib/calc.js";
  form.addEventListener("input", () =&amp;gt; { /* update from compute() */ });
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Astro bundles the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; block and leaves the frontmatter import server-side. One module, two consumers, zero duplicated arithmetic. When I changed the VAT handling, both the pre-rendered HTML and the live calculation changed together — the class of bug where server and client disagree about a number simply cannot happen.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three details worth stealing
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Currency is a parameter, not a hardcoded symbol.&lt;/strong&gt; &lt;code&gt;fmt(value, "money", "€")&lt;/code&gt; — because the same calculator exists in USD, GBP and EUR variants, and string-replacing &lt;code&gt;$&lt;/code&gt; later is how you get dollars in a eurozone page.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Rates are data, not code.&lt;/strong&gt; The VAT rate lives in the field definition (&lt;code&gt;options: ["19","20","21","22","23","24","25"]&lt;/code&gt;), so adding Hungary's 27% is a one-line change and does not touch the formula.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. The tax is displayed, not just deducted.&lt;/strong&gt; Showing &lt;code&gt;VAT collected: €3.99&lt;/code&gt; next to the payout is what makes the number believable. A single "take-home" figure invites the question "why is this so low?"; showing the line item answers it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would do differently
&lt;/h2&gt;

&lt;p&gt;I originally applied the payment percentage to the gross price and only stripped VAT at the end. It produced numbers that looked plausible and were wrong by exactly the tax rate — the worst kind of bug, because nothing crashes and the result is still in the right ballpark.&lt;/p&gt;

&lt;p&gt;The fix was not code. It was writing the formula out in plain text first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;net price = gross ÷ (1 + VAT rate)
fees      = net price × rate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If a formula cannot be written as three lines above the implementation, the implementation is doing something the author has not decided yet.&lt;/p&gt;




&lt;p&gt;The calculator this came from is free and runs entirely client-side: &lt;a href="https://ecomopskit.com/tools/tiktok-shop-fee-calculator-eu/" rel="noopener noreferrer"&gt;TikTok Shop EU fee calculator&lt;/a&gt;. There are UK and US variants built the same way, and the VAT table is one object if you want to check a rate against yours.&lt;/p&gt;

&lt;p&gt;If you are modelling EU pricing and hit a case this does not cover — reduced rates on books and children's clothing, OSS registration thresholds, IOSS consignments under €150 — I would like to hear about it. Those are the edges where a simple formula stops being enough.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>astro</category>
      <category>ecommerce</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
