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
| Name | Required | Description | Default |
|---|---|---|---|
| context | No | Optional annotation to label this calculation (e.g., 'Bond A PV', 'Q2 revenue'). Appears in results for easy identification. | |
| output_mode | No | Output format: full (default), compact, minimal, value, or final. See batch_execute tool for details. | full |
| values | Yes | Single value or list (e.g., 3.14159 or [3.14, 2.71]) | |
| method | No | Rounding method | round |
| decimals | No | Number of decimal places |
Input Schema (JSON Schema)
Implementation Reference
- src/vibe_math_mcp/tools/basic.py:180-213 (handler)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)}")
- src/vibe_math_mcp/tools/basic.py:147-179 (registration)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:
- src/vibe_math_mcp/server.py:693-693 (registration)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