Skip to content

Numeric functions

pyvider.components.functions.numeric_functions

TODO: Add module docstring.

Classes

Functions

round_number

round_number(
    number: int | float | None, *options: int
) -> int | float | None

Round a number to specified decimal places.

Parameters:

Name Type Description Default
number int | float | None

Number to round

required
*options int

Optional precision (int, default: 0)

()

Returns:

Type Description
int | float | None

Rounded number

Examples:

round_number(3.14159) → 3 round_number(3.14159, 2) → 3.14

Source code in pyvider/components/functions/numeric_functions.py
@register_function(
    name="round",
    summary="Rounds a number to a specified precision.",
    param_descriptions={
        "number": "The number to round",
        "options": "Optional: Precision (decimal places, default: 0)",
    },
)
def round_number(number: int | float | None, *options: int) -> int | float | None:
    """
    Round a number to specified decimal places.

    Args:
        number: Number to round
        *options: Optional precision (int, default: 0)

    Returns:
        Rounded number

    Examples:
        round_number(3.14159) → 3
        round_number(3.14159, 2) → 3.14
    """
    if number is None:
        return None

    # Extract precision from variadic args (default: 0)
    precision = int(options[0]) if options and len(options) > 0 else 0

    try:
        return round(number, precision)
    except TypeError as e:
        raise FunctionError(f"Invalid argument types for round: {e}") from e