Explainer

Invoice math under the hood: discount-before-tax order, zero-decimal currencies, and UTF-8 CSV encoding

How line-item multiplication, discount-before-tax ordering, zero-decimal currency rounding for IDR and JPY, and RFC 4180 CSV escaping prevent bookkeeping discrepancies.

By Max-Q Studio Team7 min read

A clean invoice looks effortless to a client, yet tiny arithmetic mismatches between a PDF invoice and an accounting spreadsheet cause hours of avoidable back-and-forth with finance teams. One penny of rounding drift, an ambiguous discount-versus-tax sequence, or broken commas inside a CSV export can delay payment approval. Here is the exact calculation and encoding architecture used inside Invoice Generator so your numbers stay transparent and auditable.

1. Exact calculation order: Subtotal, Discount, Tax, Shipping

Because percentage discounts and sales taxes are not commutative when combined with fixed fees, every invoice engine must follow a single deterministic pipeline. Invoice Generator evaluates invoice totals in this standard commercial order:

  1. Line item totalsEach row multiplies Quantity * Unit Price to produce its line amount.
  2. SubtotalAll non-empty line amounts are summed to produce the pre-adjustment Subtotal.
  3. Discount (before tax)Whether entered as a percentage (%) or a Fixed currency amount, the discount reduces the taxable subtotal first (clamped safely so discounted subtotal never drops below zero).
  4. Tax %The tax rate applies to the post-discount subtotal: Tax = (Subtotal - Discount) * (TaxRate / 100).
  5. Shipping & Grand TotalShipping is added after tax to yield the final TOTAL displayed on screen and embedded into the PDF.

Because tax jurisdictions differ on whether shipping is taxable or whether local VAT requires special registration lines, Invoice Generator provides clear live totals and a dedicated footer note field while leaving tax compliance review with you or your accountant.

2. Currency precision: 2-decimal vs zero-decimal currencies

Not every currency divides into 100 minor units. Displaying IDR 1,500,000.00 or JPY 25,000.00adds visual noise and confuses local bookkeeping software, whereas truncating cents on USD or EUR invoices creates accounting discrepancies. Inside the Tools panel of Invoice Generator, each preset currency applies appropriate decimal formatting:

Currency modeDecimal placesTypical usage
USD, EUR, GBP2 decimals (cents / pence)International consulting, software contracts, and retail goods
IDR, JPY0 decimals (whole currency units)Indonesian Rupiah and Japanese Yen invoices without trailing .00
Custom (0 to 4 decimals)User-configured symbol + precisionRegional symbols (Rp, SGD, RM), high-precision unit rates, or points

3. How A4 PDF export and print CSS stay aligned

The editable canvas in Invoice Generator is sized to real A4 proportions (210 x 297 mm) so line wrapping you see while typing mirrors your exported PDF. PressingDownload PDF generates a clean vector PDF locally in your browser without uploading client addresses, amounts, or logos. Pressing Print activates a dedicated print stylesheet that strips browser toolbars, empty placeholder rows, and input borders automatically.

4. Clean CSV export for accounting and spreadsheets

Clicking CSV exports your invoice line items as a UTF-8 CSV file formatted according to RFC 4180 rules. Multi-line item descriptions, commas inside service names, and quotation marks are properly wrapped in double quotes so Microsoft Excel, Google Sheets, and accounting tools split columns cleanly. Because Invoice Generator is local-only and stores nothing on a server, saving both the PDF (for the client) and the CSV (for your ledger) right after finishing gives you a complete offline record.

Want a complete pre-send checklist for invoice numbering and payment terms? ReadHow to write a clear freelancer or small-business invoice, or openInvoice Generator to build an A4 invoice locally.

About this guide: Written and tested by the Max-Q Studio engineering team against the real tools running on maxq.tools. Spotted something outdated or unclear? Let us know · Our editorial standards

File exceeds the size limit

Images: Max 10 MB per file. PDFs: Max 20 MB per file.