(JS) Calculate price excluding VAT

By | February 11, 2021

Sometimes you need to calculate the price of a product excluding VAT, and the only details you have is the amount including vat and the vat percent. This might be a bit tricky in some applications when there are mixed VAT percentages.

For example, you payed 1000 space credits and in that sum there is a 12% VAT included. If you need to find out how much of the 1000 is actual VAT you can use this simple function:

function getAmountWithoutVat(amountIncludingVat, vatPercent) {

  var amountExVat = amountIncludingVat / (100 + vatPercent) * 100;
  var sumVat = amountIncludingVat - amountExVat;
  var amounts = {
        'priceExVat' : amountExVat.toFixed(2),
        'vat' : sumVat.toFixed(2)

  return amounts;

console.log(getAmountWithoutVat(1000, 12));


  priceExVat: "892.86",
  vat: "107.14"

Leave a Reply

Your email address will not be published. Required fields are marked *