Rounding in Xero – an explanation
Xero may calculate line item or document totals in ways that are slightly different to other applications. Neither approach is necessarily incorrect, just slightly different.
This guide documents possible scenarios and ways to handle them via the API.
Xero calculates tax on a per line basis, rounding to two decimal places, and then sums the tax totals of each line to calculate the total invoice tax. Other systems may total lines and then calculate the tax amount, which can lead to a slight variance.
Invoice line 1: Product A @ $25.06, tax at 15%: $3.76 line total: $28.82
Invoice line 2: Product B @ $25.61, tax at 15%: $3.84 line total: $29.45
Invoice line 3: Product C @ $25.63, tax at 15%: $3.85 line total: $29.48
Xero totals: Subtotal: $76.30, Tax: $11.44
Xero document total: $87.74
Another system total: Subtotal: $76.30 + Tax @ 15%: 11.45
This can be illustrated below in Xero as the approach is the equivalent of just having one line in Xero:
All monetary calculations in Xero are to two decimals places. This can be troublesome when importing transactions into Xero from source systems that support more than 2 decimal places, particularly on unit prices.
If the source system has a line with many decimal places, eg:
Invoice line 1: 1000 x Product A @ $0.061171 (sub total of $61.17)
A better way to represent this line in Xero might be:
<LineItems> <LineItem> <Description>1000 x Product A @ $0.061171</Description> <Quantity>1</Quantity> <UnitAmount>61.17</UnitAmount> <AccountCode>200</AccountCode> </LineItem> </LineItems>
To ensure you can resolve any rounding issues, you will need to know when they occur. There are two approaches you can take:
- Apply the same logic to calculations and rounding as Xero, so your application knows in advance of any issues and can add an adjustment as required
- Read the response from the API when you have created the item, and if there is a variation between the expected total and the total in Xero, edit the item and add an adjustment line
If possible, you should add a rounding line to adjust the total to reflect the source system:
<LineItems> <LineItem> <Description>Rounding adjustment: document total $87.75</Description> <Quantity>1</Quantity> <UnitAmount>-0.01</UnitAmount> <AccountCode>860</AccountCode> </LineItem> </LineItems>
Every Xero organisation will have a rounding account, but you should ensure the account code is correct by making a GET Accounts API call at setup/configuration stage to ensure it is either the default value above, or if the user has changed it to another code, it can be found by the following element within the <Account/> element:
With the Invoices endpoint, you can now use the
Eg: on PUT or POST Invoice:
<LineItems> <LineItem> <Description>My own calculation</Description> <Quantity>7</Quantity> <UnitAmount>48.7</UnitAmount> <TaxAmount>34.10</TaxAmount> <AccountCode>200</AccountCode> </LineItem> </LineItems>
- This is currently only available on the Invoices endpoint for Tax Exclusive invoices
- TaxAmount specified cannot be greater than the UnitAmount