Math Utilities

Round Number

Rounds numbers to specified decimal places with mathematical precision. Use via MCP in Cursor or Windsurf for exact calculations, or call GET /v1/math/round?number=3.14159&places=2 to get 3.14. Handles edge cases like banker's rounding and negative numbers correctly, preventing floating-point errors that plague native JavaScript rounding.

API Endpoint

GET /v1/math/round

Code Examples

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

response = requests.get('https://tinyfn.io/v1/math/round',
    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 math tools:

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

Learn more about MCP setup →

FAQ

How do I round a number to 2 decimal places using the API?

Call GET /v1/math/round?number=3.14159&places=2 which returns 3.14. The places parameter specifies how many digits after the decimal point.

What's the difference between this and JavaScript's toFixed() method?

This tool uses proper mathematical rounding and avoids floating-point precision errors. JavaScript's toFixed() can produce unexpected results with certain decimal values due to binary representation issues.

Can I round to negative decimal places for whole number rounding?

Yes, use negative values for places parameter. For example, places=-1 rounds 1234 to 1230, and places=-2 rounds to 1200.

How does this handle banker's rounding vs standard rounding?

The tool implements standard mathematical rounding (round half up). When the digit is exactly 5, it rounds away from zero rather than using banker's rounding.

Why use this MCP tool instead of built-in rounding in my AI agent?

AI agents often hallucinate mathematical results or use imprecise calculations. This MCP tool provides deterministic, accurate rounding that your agent can rely on for financial calculations or data processing.

Try Round Number Now

Get your free API key and start using Round Number in seconds.

Get Free API Key