How should I handle reverse VAT calculations before sending invoice data through the API?

I’m working with tax-inclusive prices and need to calculate the net amount and VAT amount before sending the values to an accounting system through an API.

For example, if the total amount is £120.00 and VAT is 20%, I would expect:

  • Gross amount: £120.00
  • Net amount: £100.00
  • VAT: £20.00

The formula I’m using is:

Net = Gross ÷ (1 + VAT rate / 100)

I’m mainly trying to avoid rounding differences when the original amount has more than two decimal places.

I found it useful to verify the calculation with an online reverse sales tax calculator for finding the original price before tax, especially when testing different VAT rates.
For developers integrating tax-inclusive invoices, how do you normally handle the rounding—calculate the VAT first and derive the net amount, or calculate the net amount first and then derive the VAT?

If you search the forum you’ll find rounding on invoices has been coming up for a while.

Personally I calculate the net amount using the formula you gave. I post it to FreeAgent via the API and then read back the created invoice’s total value. If it differs from the total value I was expecting, I update the invoice with an extra item that fixes the rounding error, with the extra item’s type depending on whether the rounding error is in the net value or the tax value.