Math Utilities

Floor

Floor rounds any number down to the nearest integer, essential for array indexing, pagination, and discrete calculations. Access via MCP in Cursor or Windsurf, or call GET /v1/math/floor with your number. Returns -4 for -3.7, 5 for 5.9. Unlike ceiling, always rounds toward negative infinity regardless of sign.

API Endpoint

GET /v1/math/floor

Code Examples

curl "https://tinyfn.io/v1/math/floor" \
  -H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/math/floor', {
  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/floor',
    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 does floor handle negative numbers?

Floor always rounds toward negative infinity, so -3.2 becomes -4, not -3. This differs from truncation which would give -3.

What's the difference between floor and Math.trunc?

Floor rounds toward negative infinity while trunc removes decimals toward zero. For -2.7: floor gives -3, trunc gives -2.

Can I use floor for array indexing in MCP tools?

Yes, floor is perfect for converting floating-point calculations to valid array indices. Claude Code and Cursor can use it for pagination offsets too.

Does floor work with very large numbers?

Floor handles standard floating-point range but may lose precision with numbers beyond JavaScript's safe integer limit (2^53).

What does floor return for integers?

Floor returns integers unchanged since they're already whole numbers. 5 returns 5, -8 returns -8.

Try Floor Now

Get your free API key and start using Floor in seconds.

Get Free API Key