{"id":"price-margin-compute","version":"1.0.0","description":"Solve cost, price, profit, gross margin and markup from any two of cost, price, margin percent or markup percent.","supported_operations":["what selling price gives a 30 percent margin on cost 70","convert 25 percent markup to margin","margin and markup for cost 80 and price 100","price from cost plus 40 percent markup","what was my cost if I sell at 250 with a 35 percent margin","markup vs margin calculator","gross margin percentage of a sale","target margin price cost divided by one minus margin"],"unsupported_operations":["operating or net margin from an income statement","break-even or contribution margin analysis over volumes","discounts, taxes or fees on the price (use discount-stack-apply or vat-net-gross-convert)","currency conversion"],"semantics":["Give EXACTLY TWO of cost, price, margin_percent, markup_percent (otherwise invalid_input, reason need_exactly_two; margin_percent together with markup_percent is margin_and_markup_pair), rounding (required) and exactly one of currency (active ISO 4217 code) or scale (0..18). cost and price are non-negative money amounts that are multiples of the minor unit by value; margin_percent is 0..100 (above 100 is percent_out_of_range); markup_percent is 0 or more; percent_scale is an optional integer 0..12 (default 4).","Definitions: profit = price - cost; margin = profit / price x 100 (on the selling price); markup = profit / cost x 100 (on the cost). So 25% markup is 20% margin, and a 30% target margin needs price = cost / 0.7, not cost x 1.3.","Solving on exact rationals: (cost, margin m) gives price = cost / (1 - m/100), and m = 100 is not_computable (reason margin_100_percent) even for cost 0; (cost, markup k) gives price = cost x (1 + k/100); (price, margin m) gives cost = price x (1 - m/100); (price, markup k) gives cost = price / (1 + k/100). Every output is then derived from the exact pair, so a given percentage is re-derived at percent_scale digits.","cost, price and profit are each rounded once, independently, at the scale; margin_percent and markup_percent are each rounded once at percent_scale (fixed digits, \"20.0000\"). price - cost may therefore differ from profit in the last digit. exact is true iff no non-null output needed rounding.","The ten rounding modes: half_even, half_up (ties away from zero), half_down, half_ceiling, half_floor, up, down, ceiling, floor, and unnecessary (any inexact output is not_computable, reason rounding_necessary).","margin_percent is null exactly when the exact price is 0 and markup_percent is null exactly when the exact cost is 0 (not an error). Negative results occur only for (cost, price) with price below cost; \"-0\" never appears.","Examples: cost 80.00 and price 100.00 give profit 20.00, margin 20.0000, markup 25.0000; cost 70.00 with margin 30 gives price 100.00; cost 80.00 with markup 25 gives price 100.00; price 100.00 with markup 25 gives cost 80.00.","A decimal string over 62 characters is limit_exceeded, checked before syntax; more than 60 digits or 40 fraction digits is invalid_input. Data is the pinned ISO 4217 snapshot named by data_version; no clock, locale or network.","Disclaimer: arithmetic calculation only; not financial, tax, legal, or investment advice."],"limits":{"max_decimal_chars":62,"max_decimal_digits":60,"max_fraction_digits":40,"max_scale":18,"max_percent_scale":12},"pricing":{"status":"unpriced","charge_usd":null},"input_schema":{"type":"object","additionalProperties":false,"required":["rounding"],"properties":{"cost":{"type":"string","minLength":1,"maxLength":62,"pattern":"^(0|[1-9][0-9]*)(\\.[0-9]+)?$","description":"Unit cost, non-negative money amount (value-based precision at the scale)."},"price":{"type":"string","minLength":1,"maxLength":62,"pattern":"^(0|[1-9][0-9]*)(\\.[0-9]+)?$","description":"Selling price, non-negative money amount (value-based precision at the scale)."},"margin_percent":{"type":"string","minLength":1,"maxLength":62,"pattern":"^(0|[1-9][0-9]*)(\\.[0-9]+)?$","description":"Gross margin = profit / price x 100, from 0 to 100 inclusive."},"markup_percent":{"type":"string","minLength":1,"maxLength":62,"pattern":"^(0|[1-9][0-9]*)(\\.[0-9]+)?$","description":"Markup = profit / cost x 100, 0 or more."},"currency":{"type":"string","minLength":3,"maxLength":3,"pattern":"^[A-Za-z]{3}$","description":"Active ISO 4217 alphabetic code with a minor unit (case-insensitive). Give exactly one of currency or scale."},"scale":{"type":"integer","minimum":0,"maximum":18,"description":"Fraction digits for non-ISO units. Give exactly one of currency or scale."},"percent_scale":{"type":"integer","minimum":0,"maximum":12,"default":4,"description":"Fraction digits of the returned percentages (default 4)."},"rounding":{"type":"string","enum":["half_even","half_up","half_down","half_ceiling","half_floor","up","down","ceiling","floor","unnecessary"]}},"description":"Give EXACTLY TWO of cost, price, margin_percent, markup_percent (margin_percent with markup_percent is invalid) and exactly one of currency or scale."},"output_schema":{"type":"object","additionalProperties":false,"required":["cost","price","profit","margin_percent","markup_percent","currency","scale","exact","data_version"],"properties":{"cost":{"type":"string","minLength":1,"maxLength":400,"pattern":"^-?(0|[1-9][0-9]*)(\\.[0-9]+)?$","description":"Cost at exactly `scale` fraction digits."},"price":{"type":"string","minLength":1,"maxLength":400,"pattern":"^-?(0|[1-9][0-9]*)(\\.[0-9]+)?$","description":"Price at exactly `scale` fraction digits."},"profit":{"type":"string","minLength":1,"maxLength":400,"pattern":"^-?(0|[1-9][0-9]*)(\\.[0-9]+)?$","description":"price - cost, rounded once at the scale from the exact values (negative when price < cost)."},"margin_percent":{"type":["string","null"],"minLength":1,"maxLength":400,"pattern":"^-?(0|[1-9][0-9]*)(\\.[0-9]+)?$","description":"profit / price x 100 at percent_scale digits; null when the exact price is 0."},"markup_percent":{"type":["string","null"],"minLength":1,"maxLength":400,"pattern":"^-?(0|[1-9][0-9]*)(\\.[0-9]+)?$","description":"profit / cost x 100 at percent_scale digits; null when the exact cost is 0."},"currency":{"type":["string","null"],"pattern":"^[A-Z]{3}$"},"scale":{"type":"integer","minimum":0,"maximum":18},"exact":{"type":"boolean","description":"True when none of the five rounded outputs needed rounding."},"data_version":{"type":"string","const":"iso4217-datasets-7cdc784-2026-07-27"}}},"examples":[{"input":{"cost":"80.00","price":"100.00","currency":"USD","rounding":"half_even"},"output":{"cost":"80.00","price":"100.00","profit":"20.00","margin_percent":"20.0000","markup_percent":"25.0000","currency":"USD","scale":2,"exact":true,"data_version":"iso4217-datasets-7cdc784-2026-07-27"}},{"input":{"cost":"70.00","margin_percent":"30","currency":"USD","rounding":"half_even"},"output":{"cost":"70.00","price":"100.00","profit":"30.00","margin_percent":"30.0000","markup_percent":"42.8571","currency":"USD","scale":2,"exact":false,"data_version":"iso4217-datasets-7cdc784-2026-07-27"}},{"input":{"price":"100.00","markup_percent":"25","scale":2,"rounding":"half_up","percent_scale":2},"output":{"cost":"80.00","price":"100.00","profit":"20.00","margin_percent":"20.00","markup_percent":"25.00","currency":null,"scale":2,"exact":true,"data_version":"iso4217-datasets-7cdc784-2026-07-27"}}],"execute_url":"/v1/tools/price-margin-compute/versions/1.0.0/execute"}