Finance Utilities

Calculate Margin

Calculate profit margins instantly with precise financial math. Access via MCP in Cursor or Claude Code, or through REST API at `/v1/finance/margin`. Input revenue and cost to get gross margin percentage — essential for pricing decisions, financial analysis, and business planning. Returns standardized decimal format for consistent calculations.

API Endpoint

GET /v1/finance/margin

Code Examples

curl "https://tinyfn.io/v1/finance/margin" \
  -H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/finance/margin', {
  headers: { 'X-API-Key': 'YOUR_API_KEY' }
});
const data = await response.json();
console.log(data);
import requests

response = requests.get('https://tinyfn.io/v1/finance/margin',
    headers={'X-API-Key': 'YOUR_API_KEY'})
data = response.json()
print(data)

Use via MCP

Add to your AI agent

Connect your AI agent (Claude, Cursor, Windsurf, etc.) to TinyFn's finance tools:

{
  "mcpServers": {
    "tinyfn-finance": {
      "url": "https://tinyfn.io/mcp/finance",
      "headers": {
        "X-API-Key": "YOUR_API_KEY"
      }
    }
  }
}

Learn more about MCP setup →

FAQ

How do I calculate profit margin using this tool?

Provide revenue and cost values to get the margin percentage. Formula is (revenue - cost) / revenue × 100. Returns precise decimal results for financial accuracy.

What's the difference between gross margin and markup?

Margin calculates profit as percentage of revenue, while markup calculates profit as percentage of cost. This tool computes margin — more common in financial reporting.

Can I use this in MCP tools for financial analysis workflows?

Yes, integrate with Cursor, Windsurf, or other MCP-enabled editors for automated margin calculations in spreadsheets, reports, and pricing models.

What happens with negative margins or zero revenue?

Handles negative margins (losses) correctly. Zero revenue returns undefined/error to prevent division by zero in financial calculations.

Does this tool round results for financial reporting?

Returns full precision decimal values. You control rounding based on your accounting standards or reporting requirements.

Try Calculate Margin Now

Get your free API key and start using Calculate Margin in seconds.

Get Free API Key