def format_value(value, fmt):
    """
    Convert numerical value to string with a specific format

    Parameters
    ----------
    value : int or float
        Numerical variable to convert.
    fmt : str
        String format used to apply the conversion

    Returns
    -------
    string_value : str
        String containing a formatted version of the value

    Examples
    --------
    >>> format_value(30.5, ".3f")
    '30.500'
    >>> format_value(30.5, "5g")
    '30.5'
    >>> format_value(123, "d")
    '123'
    >>> format_value(123, ".2f")
    '123.00'

    """
    return "{value:>{fmt}}".format(value=value, fmt=fmt).strip()