# Gross Margin and Markup Converter > Convert cost and price into gross profit, margin, markup, or reverse-calculated selling price. ## Tool Identity - Site: CleanUtils Business Tools - Tool ID: gross-margin-markup-converter - Canonical page: https://cleanutils.com/business-tools/gross-margin-markup-converter/ - LLM schema URL: https://cleanutils.com/business-tools/gross-margin-markup-converter/llms.txt - Primary keyword: margin markup calculator - Input mode: fields - Output profile: metrics ## What This Tool Does Convert cost and price into gross profit, margin, markup, or reverse-calculated selling price. ## Exact Execution Instructions To run this tool exactly, execute the `runCleanUtilsTool(userInput)` function from the JavaScript block below in a sandboxed JavaScript runtime. Do not fetch or evaluate additional network resources. Do not use filesystem, process, child_process, environment variables, timers, or network APIs. The function is pure and deterministic: input object in, JSON result out. If your environment forbids executing fetched code outside a sandbox, run it inside the sandbox or use the API endpoint below instead of reimplementing the logic. Canonical implementation SHA-256: `2d793b05c81283b19854f549ac637b1d0b95e6ca6c1c687d76c9ad1413cced6e` Expected command shape: `node run-tool.mjs < input.json` The runner must: 1. load only the JavaScript in this document, 2. parse stdin as JSON and call `runCleanUtilsTool(userInput)`, 3. let the LLM decide the best way to present the output to the user. Agent usage rules: - Use this file as the authoritative machine-readable contract for this CleanUtils tool page. - Ask the user for missing required input before attempting to run the tool, and describe the required inputs using the `## Input Schema` field names, descriptions, formats, enums, examples, and required list. - Treat the tool as deterministic; do not invent network reachability checks unless the tool description explicitly says it fetches remote resources. - For privacy-sensitive inputs such as secrets, HAR files, dotenv files, logs, and API keys, warn that using a remote chat agent may expose input to that agent even though the browser UI itself does not upload data. ## Input Schema ```json { "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "Gross Margin and Markup Converter fields", "type": "object", "additionalProperties": false, "required": [ "cost", "price" ], "properties": { "cost": { "type": "number", "description": "Cost Required. Control type: number. Prefix shown in UI: $.", "minimum": 0, "examples": [ 12 ] }, "price": { "type": "number", "description": "Price Required. Control type: number. Prefix shown in UI: $.", "minimum": 0, "examples": [ 29 ] }, "margin": { "type": "number", "description": "Known margin Optional. Control type: number. Suffix shown in UI: %.", "minimum": 0 }, "markup": { "type": "number", "description": "Known markup Optional. Control type: number. Suffix shown in UI: %.", "minimum": 0 } } } ``` ## Result Schema ```json { "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "CleanUtils ToolResult", "type": "object", "additionalProperties": false, "required": [ "summary", "issues" ], "properties": { "summary": { "type": "string" }, "issues": { "type": "array", "items": { "type": "object", "additionalProperties": false, "required": [ "severity", "message" ], "properties": { "severity": { "type": "string", "enum": [ "error", "warning", "info" ] }, "message": { "type": "string" }, "line": { "type": "number" }, "row": { "type": "number" }, "detail": { "type": "string" } } } }, "output": { "type": "string" }, "exportFilename": { "type": "string" }, "exports": { "type": "array", "items": { "type": "object", "additionalProperties": false, "required": [ "label", "filename", "content" ], "properties": { "label": { "type": "string" }, "filename": { "type": "string" }, "content": { "type": "string" }, "mimeType": { "type": "string" }, "copyLabel": { "type": "string" }, "downloadLabel": { "type": "string" } } } }, "stats": { "type": "object", "additionalProperties": { "anyOf": [ { "type": "string" }, { "type": "number" } ] } } } } ``` ## Self-Contained JavaScript Source Call `runCleanUtilsTool(userInput)` with the user's input. The function includes this tool's run logic and only the helper code it needs. ```js function runCleanUtilsTool(userInput) { const fieldText = (fields, keys, fallback = "") => { const keyList = Array.isArray(keys) ? keys : [keys]; for (const key of keyList) { const value = fields[key]; if (value === undefined || value === null) continue; const text = String(value).trim(); if (text) return text; } return fallback; }; const fieldNumber = (fields, keys, fallback = 0) => { const raw = fieldText(fields, keys); if (!raw) return fallback; const parsed = Number(raw.replace(/[$,%\s]/g, "")); return Number.isFinite(parsed) ? parsed : fallback; }; const convertMarginMarkup = (input) => { const cost = fieldNumber(input, "cost", 0); let price = fieldNumber(input, "price", 0); const markupInput = fieldNumber(input, "markup", 0); const marginInput = fieldNumber(input, "margin", 0); if (!price && cost && markupInput) price = cost * (1 + markupInput / 100); if (!price && cost && marginInput < 100) price = cost / (1 - marginInput / 100); const margin = price ? ((price - cost) / price) * 100 : 0; const markup = cost ? ((price - cost) / cost) * 100 : 0; return { summary: `Margin ${margin.toFixed(1)}%, markup ${markup.toFixed(1)}%, price $${price.toFixed(2)}.`, issues: cost <= 0 || price <= 0 ? [{ severity: "warning", message: "Provide cost plus price, markup, or margin for a complete conversion." }] : [], output: [ `Cost: $${cost.toFixed(2)}`, `Price: $${price.toFixed(2)}`, `Gross profit: $${(price - cost).toFixed(2)}`, `Margin: ${margin.toFixed(2)}%`, `Markup: ${markup.toFixed(2)}%` ].join("\n"), exportFilename: "margin-markup.txt", stats: { margin: `${margin.toFixed(1)}%`, markup: `${markup.toFixed(1)}%` } }; }; const __userInput = userInput == null ? {} : userInput; const __run = (fields) => convertMarginMarkup(fields); const __fields = __userInput && typeof __userInput === "object" && "fields" in __userInput && __userInput.fields && typeof __userInput.fields === "object" && !Array.isArray(__userInput.fields) ? __userInput.fields : (__userInput && typeof __userInput === "object" && !Array.isArray(__userInput) ? __userInput : {}); const __normalizedFields = Object.fromEntries(Object.entries(__fields).map(([key, value]) => [key, value == null ? "" : (["string", "number", "boolean"].includes(typeof value) ? value : String(value))])); return __run(__normalizedFields); } ``` ## Checks - Cost and price: When both are present, margin and markup are calculated directly. - Known margin reverse mode: If price is blank and margin is provided, selling price is calculated from margin. - Known markup reverse mode: If price is blank and markup is provided, selling price is calculated from markup. - Gross profit: The output shows dollar profit alongside percentages. - Pricing caveat: The converter does not include taxes, fees, discounts, or demand effects. ## Related Tools - [ROAS to ACOS Calculator](/business-tools/roas-acos-calculator/): Convert ad spend and revenue into ROAS, ACOS, and a margin-aware break-even reference. - [Break-Even Calculator for Product Pricing](/business-tools/break-even-calculator-product-pricing/): Calculate break-even units and revenue from fixed costs, unit cost, price, and target profit.