Every billing developer in India eventually gets a call: "the invoice total is 1 paisa off from the GST return." Almost always the cause is rounding at the wrong step, or using double.
1. Use decimal, never double
double cannot represent 0.1 exactly, so 0.1 + 0.2 is not 0.3. Money must be decimal in C# and DECIMAL(18,2) (or more scale for rates) in SQL Server.
decimal taxable = 1234.56m; decimal rate = 18m; decimal gst = Math.Round(taxable * rate / 100m, 2, MidpointRounding.AwayFromZero); 2. Pick a midpoint rule and use it everywhere
.NET's default Math.Round uses banker's rounding (ToEven): 2.345 becomes 2.34. Most accountants expect 2.35. Pass MidpointRounding.AwayFromZero explicitly, and use the same rule in SQL (ROUND() in SQL Server rounds half away from zero for decimals).
3. Decide: round per line or per invoice
- Per line: compute tax on each line, round it, then sum. Line totals print cleanly.
- Per invoice: sum taxable values by rate, compute tax once, round once.
Both are defensible; mixing them is not. Store which one you use and keep the same logic in the invoice print, e-invoice JSON and GSTR-1 export.
4. CGST + SGST splitting
Compute the total intra-state tax first, round it, then split. If the total is odd in paise, give the extra paisa to one side consistently:
decimal totalTax = Math.Round(taxable * rate / 100m, 2, MidpointRounding.AwayFromZero); decimal cgst = Math.Round(totalTax / 2m, 2, MidpointRounding.AwayFromZero); decimal sgst = totalTax - cgst; // always adds up 5. Round-off to the rupee goes in its own line
If you round the grand total to the nearest rupee, post the difference to a "Round Off" ledger. Never adjust tax or taxable value to absorb it.
Checklist
-
decimalend to end, including DTOs and JSON serialization - One midpoint rule, set explicitly
- One rounding level (line or invoice), documented
- Split CGST/SGST by subtraction
- Separate round-off line and ledger
Author note: I work on Speed Plus 9, a GST billing and ERP product (solversolutions.in/speed).