How do I find the exact total of the cart(Javascript)

I have made an online food ordering website all is done but I don’t know I am getting sum BUG in finding the total
The javascript updatecartTotal() method which finds total goes like this

   
    var cartItemContainer = document.getElementsByClassName('cart-items')[0]
    var rowvar = cartItemContainer.getElementsByClassName('cart-row')
    var total = 0
    

    
    for (var i = 0; i < rowvar.length; i++) {
        var rowvar = rowvar[i]
        var priceElement = rowvar.getElementsByClassName('cart-price')[0]
        var quantityElement = rowvar.getElementsByClassName('cart-quantity-input')[0]
        var price = parseFloat(priceElement.innerText.replace('₹', ''))
        var quantity = parseInt(quantityElement.value)
        z = (price * quantity)
        console.log(price)
        console.log(z)
        console.log(quantity)
        total = (Math.round(z*5/100))  + (quantity*total) + (z)
        
        console.log(total)
    }
}

I want a gst of 5 percent NOT ON ULTIMATE FINAL PRICE
I want it on final price of each food item then add all final prices to get ULTIMATE FINAL PRICE which is our total.It is quite confusing bug for me hope you can solve it.

Here price is just the price per piece of item

Thank You