FINANCE

GST Calculator

Add or remove GST instantly. See CGST, SGST, and IGST breakdown.

TOTAL WITH GST

₹0
Base Amount
GST Amount
CGST
SGST
Developer Reference

Core Algorithm & Standalone Script

Standalone, zero-dependency JavaScript implementation powering this tool. Free to inspect, copy, and build upon.

function fmt(n) { return n.toLocaleString('en-IN', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); }
  function fmtRs(n) { return '₹' + fmt(n); }

  let mode = 'add', rate = 18;

  document.querySelectorAll('#mode-tabs .tab').forEach(t => {
    t.addEventListener('click', () => {
      document.querySelectorAll('#mode-tabs .tab').forEach(x => x.classList.remove('active'));
      t.classList.add('active');
      mode = t.dataset.mode;
      document.getElementById('amount-label').textContent = mode === 'add' ? 'Amount (₹) — before GST' : 'Amount (₹) — including GST';
      document.getElementById('result-label').textContent = mode === 'add' ? 'TOTAL WITH GST' : 'BASE PRICE (EXCL. GST)';
      calc();
    });
  });

  document.querySelectorAll('#rate-group .toggle-item').forEach(t => {
    t.addEventListener('click', () => {
      document.querySelectorAll('#rate-group .toggle-item').forEach(x => x.classList.remove('active'));
      t.classList.add('active');
      rate = parseFloat(t.dataset.rate);
      calc();
    });
  });

  document.getElementById('inp-amount').addEventListener('input', calc);

  function calc() {
    const amount = parseFloat(document.getElementById('inp-amount').value) || 0;
    let base, gst, total;
    if (mode === 'add') {
      base = amount;
      gst = amount * rate / 100;
      total = base + gst;
    } else {
      total = amount;
      base = amount / (1 + rate / 100);
      gst = total - base;
    }
    const half = gst / 2;
    document.getElementById('val-total').textContent = fmtRs(mode === 'add' ? total : base);
    document.getElementById('val-base').textContent = fmtRs(base);
    document.getElementById('val-gst').textContent = fmtRs(gst);
    document.getElementById('val-cgst').textContent = fmtRs(half);
    document.getElementById('val-sgst').textContent = fmtRs(half);
  }
  calc();