Backend & APIsSeptember 23, 2026•8 min read

Precision Invoicing for Developers: Calculating Indian GST (CGST, SGST, IGST) & Global VAT

Eliminating floating-point rounding errors in financial invoicing software. Understanding intra-state vs inter-state GST rules.

RB
Rohit Bhatu — Lead Systems Architect
Precision Invoicing for Developers: Calculating Indian GST (CGST, SGST, IGST) & Global VAT

1. The Danger of IEEE 754 Floating-Point in Financial Code

JavaScript and many backend runtimes use binary IEEE 754 double-precision floating-point numbers. In this format, fractions like `0.1 + 0.2` equal `0.30000000000000004`.

When calculating taxes across dozens of line items, cumulative rounding errors cause calculated totals to differ from printed line sums by 1 or 2 cents, resulting in invoice rejection and audit flags.

Always perform financial calculations using integer cents (multiplying currency values by 100) or specialized arbitrary-precision libraries like `decimal.js`.

2. Intra-State vs. Inter-State GST Rules

Under the Indian Goods and Services Tax (GST) framework, taxation depends on whether the supplier and recipient are in the same state:

• Intra-State Transaction (Supplier State == Customer State): Tax is split equally into Central GST (CGST) and State GST (SGST). For an 18% tax rate, 9% is CGST and 9% is SGST.

• Inter-State Transaction (Supplier State != Customer State): The full tax rate applies as Integrated GST (IGST) (18%).

Precision arithmetic GST calculator functiontypescript
export interface InvoiceItem {
  description: string;
  quantity: number;
  unitPriceCents: number;
  taxRatePercent: number;
}

export function calculateGstSummary(
  items: InvoiceItem[],
  isInterState: boolean
) {
  let subtotalCents = 0;
  let totalTaxCents = 0;

  for (const item of items) {
    const lineTotalCents = item.quantity * item.unitPriceCents;
    const lineTaxCents = Math.round((lineTotalCents * item.taxRatePercent) / 100);

    subtotalCents += lineTotalCents;
    totalTaxCents += lineTaxCents;
  }

  const grandTotalCents = subtotalCents + totalTaxCents;

  return {
    subtotal: subtotalCents / 100,
    cgst: isInterState ? 0 : (totalTaxCents / 2) / 100,
    sgst: isInterState ? 0 : (totalTaxCents / 2) / 100,
    igst: isInterState ? totalTaxCents / 100 : 0,
    grandTotal: grandTotalCents / 100,
  };
}

3. Generating Printable PDFs in the Browser

Modern web applications can trigger print styling via `@media print` CSS rules, producing clean PDF invoices without requiring heavy server-side headless Chrome instances.

Create tax-compliant invoices supporting GST and VAT instantly using our Freelance Invoice Generator.