Profit margin and markup calculator

Calculate gross profit, markup based on cost, and gross margin based on selling price.

Both amounts must use the same currency. Fees, taxes and currency conversion are not included.

Both dots and commas are accepted as decimal separators.

Your inputs stay in your browser.

Method and assumptions

Method version 1.0.0 · Updated

Calculate margin

Formula: Profit = selling price − cost; markup = profit ÷ cost; gross margin = profit ÷ selling price.

Both amounts must use the same currency. Fees, taxes and currency conversion are not included.

cost
Cost
salePrice
Selling price

Enter cost and selling price in the same currency. Markup is profit divided by cost; gross margin is profit divided by selling price. Results are rounded to two decimal places for display. A loss-making sale is allowed.

Calculate with code

These short examples use the same inputs and core calculation as this tool. Adapt validation and formatting to your application.

JavaScript
const salePrice = 50, cost = 30;
const profit = salePrice - cost;
console.log(profit, profit / cost * 100, profit / salePrice * 100); // 20, 66.67% margin, 40% markup
TypeScript
const salePrice = 50, cost = 30;
const profit = salePrice - cost;
console.log(profit, profit / cost * 100, profit / salePrice * 100); // 20, 66.67%, 40%
Python
sale, cost = 50, 30
profit = sale - cost
print(profit, profit / cost * 100, profit / sale * 100)  # 20, 66.67, 40
Java
double sale = 50, cost = 30, profit = sale - cost;
System.out.printf("%.0f %.2f%% %.0f%%%n", profit, profit / cost * 100, profit / sale * 100); // 20 66.67% 40%
C#
decimal sale = 50, cost = 30, profit = sale - cost;
Console.WriteLine($"{profit} {profit / cost * 100:F2}% {profit / sale * 100}%"); // 20 66.67% 40%