<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[ClearCalc Notes]]></title><description><![CDATA[ClearCalc Notes]]></description><link>https://clearcalc-notes.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sun, 15 Nov 2026 21:11:20 GMT</lastBuildDate><atom:link href="https://clearcalc-notes.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Reverse sales tax: how to find the pre-tax price from a receipt total (with JavaScript)]]></title><description><![CDATA[Disclosure: I'm Zayed and I build ClearCalc Tools, a free calculator site. This post explains the math behind one of its features. A very common mistake…]]></description><link>https://clearcalc-notes.hashnode.dev/reverse-sales-tax-how-to-find-the-pre-tax-price-from-a-receipt-total-with-javascript</link><guid isPermaLink="true">https://clearcalc-notes.hashnode.dev/reverse-sales-tax-how-to-find-the-pre-tax-price-from-a-receipt-total-with-javascript</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[Tutorial]]></category><category><![CDATA[Math]]></category><dc:creator><![CDATA[Zayed]]></dc:creator><pubDate>Thu, 12 Nov 2026 04:26:15 GMT</pubDate><content:encoded><![CDATA[<p>Disclosure: I'm Zayed and I build ClearCalc Tools, a free calculator site. This post explains the math behind one of its features.</p>
<p>A very common mistake when you want the price <em>before</em> tax is to subtract the tax rate from the total. If you paid $108.00 with 8% sales tax, the pre-tax price is <strong>not</strong> $108 × 0.92 = $99.36.</p>
<h2>Why subtracting the percentage is wrong</h2>
<p>Sales tax is charged on the pre-tax price:</p>
<pre><code>total = price × (1 + rate)
</code></pre>
<p>So to go backwards you divide, you don't multiply by (1 − rate):</p>
<pre><code>price = total / (1 + rate)
tax   = total − price
</code></pre>
<p>For $108.00 at 8%: 108 / 1.08 = <strong>$100.00</strong>, and the tax is $8.00. The "subtract 8%" method undercounts by 64 cents, and the error grows with the rate and the amount.</p>
<h2>In code</h2>
<pre><code class="language-js">function reverseSalesTax(total, ratePercent) {
  const rate = ratePercent / 100;
  const price = total / (1 + rate);
  // round to cents only at the end
  const priceCents = Math.round(price * 100);
  const taxCents = Math.round(total * 100) - priceCents;
  return { price: priceCents / 100, tax: taxCents / 100 };
}

console.log(reverseSalesTax(108, 8));      // { price: 100, tax: 8 }
console.log(reverseSalesTax(54.27, 7.25)); // { price: 50.6, tax: 3.67 }
</code></pre>
<p>Working in integer cents for the final split guarantees that <code>price + tax</code> always equals the receipt total exactly, which matters if you show both numbers to a user.</p>
<h2>Gotchas</h2>
<ul>
<li><strong>Combined rates.</strong> In the US the rate on a receipt is usually state + county + city (+ special district). Use the combined rate, not just the state base rate.</li>
<li><strong>Rounding per line vs per receipt.</strong> Stores often round tax per item, so reversing a whole-receipt total can be off by a cent or two.</li>
<li><strong>Exempt items.</strong> Groceries, clothing or prescriptions are exempt or taxed differently in many states, so a mixed receipt can't be reversed with one rate.</li>
<li><strong>VAT/GST works the same way.</strong> UK VAT at 20%: divide by 1.2. Australian GST at 10%: divide by 1.1 (i.e. the GST is 1/11 of the total).</li>
</ul>
<p>If you just need a quick number, I keep a free sales tax calculator here: <a href="https://clearcalctools.com/calculators/sales-tax-calculator/">https://clearcalctools.com/calculators/sales-tax-calculator/</a> (free, no sign-up).</p>
<p>How do you handle per-line rounding when reconstructing receipts? Curious what others do.</p>
]]></content:encoded></item></channel></rss>