gross profit and gross profit percentage

We calculate Gross Profit = Selling Price – Purchase Price.
Gross Profit Percentage = (Gross Profit / Selling Price) * 100.

If item line consists of selling price and purchase price, then use this function to calculate gross profit and gross profit percentage.

  function calculateGrossProfitAndPercentage(sellingPrice, purchasePrice) {
        try {
            if (sellingPrice && purchasePrice) {
                let grossProfit = sellingPrice - purchasePrice;
                let grossProfitPercentage = (grossProfit / sellingPrice) * 100;
                grossProfitPercentage = parseFloat(grossProfitPercentage.toFixed(2));
                return {
                    grossProfit: grossProfit,
                    grossProfitPercentage: grossProfitPercentage
                };
            }
            return null;
        }
        catch (err) {
            log.error("error@calculateGrossProfitAndPercentage", err);
        }
    }

Leave a comment

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