Quantity calculation