Skip to main content
Glama
apetta
by apetta

round

Perform advanced rounding operations using multiple methods including round to nearest, floor, ceil, and truncate. Specify decimal places and handle single values or lists for 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

TableJSON 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

Implementation Reference

  • Registers the 'round' MCP tool with detailed description, input schema (values: Union[float, List[float]], method: Literal['round','floor','ceil','trunc'], decimals: int), and annotations.
    @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, ), )
  • Executes the rounding logic: handles single value or list, uses NumPy functions (np.round, np.floor, np.ceil, np.trunc) scaled by 10**decimals, formats result with format_result.
    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)}")

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