1 min

Calculations in Wix Velo

Updated: Apr 12

Need to do calculations in Wix Velo? This is an example that shows you how to multiply, divide, and sum using input fields, text elements, and Wix Velo.

The example below is a simple calculation with only the product quantity as an input field. By changing the quantity of the product, the total price excluding VAT, the VAT, and the total price including VAT all automatically change.

This is the setup in the Wix Editor:

This is the page code:

export function Quantity_change(event) {

    let price = Number($w('#ProductPrice').text);

    let quantity = Number(event.target.value);

    $w('#TotPriceExclVAT').text = String(quantity * price);

    let percentage = Number($w('#Per').text);

    let priceexvat = Number($w('#TotPriceExclVAT').text);

    $w('#VAT').text = String(percentage * priceexvat / 100);

    $w('#TotPriceInclVAT').text = String(Number($w('#TotPriceExclVAT').text) + Number($w('#VAT').text));

    }

This is how it looks on the live site after the quantity has been changed:

Pay attention that coding summation requires a totally different approach than multiplication and dividing!

For more examples of calculations with Wix Code / Corvid, have a look at our tutorial pages Multiple Numbers Using Wix Code and Add Up Numbers with Wix Code.

Do you need help with Wix Code, or would you like us to design a beautiful, functional, and relevant Wix website for you? Contact WixCreate, we will create an online presence that works for you.