Skip to main content
Glama
by apetta

round

Round numbers using multiple methods: nearest, floor (down), ceil (up), or truncate. Specify decimal places for precise mathematical calculations.

Instructions

Advanced rounding operations with multiple methods.

Methods: - round: Round to nearest (3.145 → 3.15 at 2dp) - floor: Always round down (3.149 → 3.14) - ceil: Always round up (3.141 → 3.15) - trunc: Truncate towards zero (-3.7 → -3, 3.7 → 3)

Examples:

ROUND TO NEAREST: values=3.14159, method="round", decimals=2 Result: 3.14

FLOOR (DOWN): values=3.14159, method="floor", decimals=2 Result: 3.14

CEIL (UP): values=3.14159, method="ceil", decimals=2 Result: 3.15

MULTIPLE VALUES: values=[3.14159, 2.71828], method="round", decimals=2 Result: [3.14, 2.72]

Input Schema

NameRequiredDescriptionDefault
contextNoOptional annotation to label this calculation (e.g., 'Bond A PV', 'Q2 revenue'). Appears in results for easy identification.
output_modeNoOutput format: full (default), compact, minimal, value, or final. See batch_execute tool for details.full
valuesYesSingle value or list (e.g., 3.14159 or [3.14, 2.71])
methodNoRounding methodround
decimalsNoNumber of decimal places

Input Schema (JSON Schema)

{ "properties": { "context": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "Optional annotation to label this calculation (e.g., 'Bond A PV', 'Q2 revenue'). Appears in results for easy identification." }, "decimals": { "default": 0, "description": "Number of decimal places", "minimum": 0, "type": "integer" }, "method": { "default": "round", "description": "Rounding method", "enum": [ "round", "floor", "ceil", "trunc" ], "type": "string" }, "output_mode": { "default": "full", "description": "Output format: full (default), compact, minimal, value, or final. See batch_execute tool for details.", "enum": [ "full", "compact", "minimal", "value", "final" ], "type": "string" }, "values": { "anyOf": [ { "type": "number" }, { "items": { "type": "number" }, "type": "array" } ], "description": "Single value or list (e.g., 3.14159 or [3.14, 2.71])" } }, "required": [ "values" ], "type": "object" }

Implementation Reference

  • The main handler function `round_values` that performs the rounding using NumPy functions based on the specified method (round, floor, ceil, trunc). Supports single values or lists.
    async def round_values( values: Annotated[ Union[float, List[float]], Field(description="Single value or list (e.g., 3.14159 or [3.14, 2.71])"), ], method: Annotated[ Literal["round", "floor", "ceil", "trunc"], Field(description="Rounding method") ] = "round", decimals: Annotated[int, Field(description="Number of decimal places", ge=0)] = 0, ) -> str: """Advanced rounding operations.""" try: is_single = isinstance(values, (int, float)) vals = [values] if is_single else values arr = np.array(vals, dtype=float) if method == "round": result = np.round(arr, decimals) elif method == "floor": result = np.floor(arr * 10**decimals) / 10**decimals elif method == "ceil": result = np.ceil(arr * 10**decimals) / 10**decimals elif method == "trunc": result = np.trunc(arr * 10**decimals) / 10**decimals else: raise ValueError(f"Unknown method: {method}") final_result = float(result[0]) if is_single else result.tolist() return format_result(final_result, {"method": method, "decimals": decimals}) except Exception as e: raise ValueError(f"Rounding operation failed: {str(e)}")
  • The `@mcp.tool` decorator registers the 'round' tool with name, description, and ToolAnnotations.
    @mcp.tool( name="round", description="""Advanced rounding operations with multiple methods. Methods: - round: Round to nearest (3.145 → 3.15 at 2dp) - floor: Always round down (3.149 → 3.14) - ceil: Always round up (3.141 → 3.15) - trunc: Truncate towards zero (-3.7 → -3, 3.7 → 3) Examples: ROUND TO NEAREST: values=3.14159, method="round", decimals=2 Result: 3.14 FLOOR (DOWN): values=3.14159, method="floor", decimals=2 Result: 3.14 CEIL (UP): values=3.14159, method="ceil", decimals=2 Result: 3.15 MULTIPLE VALUES: values=[3.14159, 2.71828], method="round", decimals=2 Result: [3.14, 2.72]""", annotations=ToolAnnotations( title="Advanced Rounding", readOnlyHint=True, idempotentHint=True, ), )
  • Pydantic-style input schema defined via Annotated types for values (float or list[float]), method (enum), and decimals (int >=0).
    values: Annotated[ Union[float, List[float]], Field(description="Single value or list (e.g., 3.14159 or [3.14, 2.71])"), ], method: Annotated[ Literal["round", "floor", "ceil", "trunc"], Field(description="Rounding method") ] = "round", decimals: Annotated[int, Field(description="Number of decimal places", ge=0)] = 0, ) -> str:
  • Import of tools.basic module in server.py triggers the decorator-based registration of the 'round' tool.
    from .tools import array, basic, batch, calculus, financial, linalg, statistics # noqa: E402

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/apetta/vibe-math-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server