Skip to content

Instantly share code, notes, and snippets.

@gmacdougall
Created January 15, 2015 14:04
Show Gist options
  • Save gmacdougall/4e203e9761d20103911e to your computer and use it in GitHub Desktop.
Save gmacdougall/4e203e9761d20103911e to your computer and use it in GitHub Desktop.
Sample Sales Tax Scenarios

Basic Scenarios (no exchanges)

Scenario 1

Consider a 10% sales tax.

Line Item 1 (Quantity 1) @ $0.04 = $0.04
Line Item 2 (Quantity 1) @ $0.04 = $0.04

Should the tax charged on this order be:

  • $0.00 ($0.004 for each line item, rounded down to $0.00) (0.04 * 0.1).round(2) * 2

  • $0.01 ($0.004 * 2 = $0.008, rounded up to $0.01) (0.04 * 0.1 * 2).round(2)

Scenario 2

Consider a 10% sales tax.

Line Item 1 (Quantity 2) @ $0.03 = $0.06
Line Item 2 (Quantity 2) @ $0.03 = $0.06

Should the tax charged on this order be:

  • $0.00 ($0.003 for each individual item, rounded down to $0.00) (0.03 * 0.1).round(2) * 4

  • $0.01 ($0.006 for each line item, summed to $0.012, then rounded down to $0.01) ((0.03 * 0.1 * 2) * 2).round(2)

  • $0.02 ($0.004 * 2 = $0.008, rounded up to $0.01) (0.03 * 0.1 * 2).round(2) * 2

Advanced Scenarios (returns & exchanges involved)

Scenario 1

Consider a 10% sales tax.

Line Item 1 (Quantity 3) @ $0.06 = $0.18

How much tax was charged on this order?

How much tax would be refunded when some set of the three items are returned?

Example:

I would expect that the order would be charged $0.02 tax. This is due to a subtotal of $0.18, which @ 10% leads to $0.018, rounded up to $0.02 tax.

Line Item 1 (Quantity 3) @ $0.06 = $0.18
Subtotal                           $0.18
Tax (10%)                          $0.02
Order Total                        $0.20

If I return one item, I would expect that I would receive a refund of $0.07, ($0.06 for the item, $0.01 for the tax)

At some point later, I return a second item. Does it give back $0.06 or $0.07?

At some point later, I return the third item. Does it give back $0.06 or $0.07?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment