Compute Zoho Books Invoice Totals With Discounts And Tax Rounding
Last updated: November 29, 2026
Quick Overview
Given invoice line items with quantity, rate, optional line discount and a tax percentage, plus an optional invoice-level discount, compute the subtotal, discount, tax per tax rate and grand total, rounded to two decimals the way an accounting product must.
Zoho
November 29, 20260
0
0 solved
Given invoice line items with quantity, rate, optional line discount and a tax percentage, plus an optional invoice-level discount, compute the subtotal, discount, tax per tax rate and grand total, rounded to two decimals the way an accounting product must.
Zoho Books generates invoices for businesses in many tax regimes, including India's GST with several slab rates, so the totals on a PDF must match what the accountant computes by hand. The interviewer is checking decimal arithmetic instead of floats, a stated rounding policy and the order in which discounts and tax are applied.
What the Interviewer Expects
- Use Decimal (or integer minor units), never binary floats, for money
- State and apply a rounding mode such as half-up
- Apply discounts before tax and explain why
- Group tax by rate so the invoice shows one line per slab
- Make the total equal the sum of the displayed components
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Should tax be rounded per line or per rate group, and what changes if a country requires per-line?
- How would you support tax-inclusive prices?
- How do you handle currencies with zero or three minor digits?
- How would you test this against an accountant's expected output?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Lines: qty, rate, tax_pct, optional line_discount_pct. Invoice discount is a percentage applied to the subtotal before tax. Round each line amount to cents, compute tax on the discounted base ...
High-Level Design
Convert every input through str to Decimal so 0.1 stays exact. Accumulate a taxable base per tax rate. Apply the invoice discount factor to each base before computing its tax, so the tax lines a...