# 9 examples of 'python round to nearest 10' in Python

Every line of 'python round to nearest 10' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

## All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
``248def nearest(n):249    """250    round up or down to nearest int returning an int251252    Used for selecting the nearest pixel position.253254    WARNING, this method is vectorised to handle a numpy array by NumpyImage255256    :param a number or array of numbers: virtual pixel position (x or y)257    :return int: nearest integer (round up/down)258    """259    if type(n) is None: return260    n=float(n) # make sure n is a float261    return int(round(n,0))``
``71def roundup(n, q):72    import math73    return int(math.ceil(float(n) / float(q)) * q)``
``238def round2 (n):239    """ Get nearest power of two superior to n """240    f = 1241    while f``
``312def p_round(n, precision=5):313    precision = int(precision)314    return int(round(n / float(precision))) * precision``
``4def round_down(v):5    return (int(v[0]), int(v[1]))``
``50def closest(number, ndigits=0, resolution=None):51    """Round a number defining the number of precision decimal digits and52    the resolution.5354    Examples55    --------5657    &gt;&gt;&gt; closest(103.66778,)58    104.059    &gt;&gt;&gt; closest(103.66778, ndigits=2)60    103.6761    &gt;&gt;&gt; closest(103.66778, ndigits=2, resolution=5)62    105.063    &gt;&gt;&gt; closest(103.66778, ndigits=2, resolution=0.5)64    103.565    &gt;&gt;&gt; closest(103.66778, ndigits=2, resolution=0.25)66    103.7567    """68    num = round(number, ndigits)69    return (num if resolution is None else70            round((num // resolution * resolution +71                   round((num % resolution) / float(resolution), 0) *72                   resolution), ndigits))``
``17def round_up(x, base=1):18  return int(base * round(float(x)/base))``
``576def _round_frac(x, precision):577    """578    Round the fractional part of the given number579    """580    if not np.isfinite(x) or x == 0:581        return x582    else:583        frac, whole = np.modf(x)584        if whole == 0:585            digits = -int(np.floor(np.log10(abs(frac)))) - 1 + precision586        else:587            digits = precision588        return np.around(x, digits)``
``631def rpy_round(number, ndigits):632    # Algorithm copied directly from CPython633634    if number == 0 or rfloat.isinf(number) or rfloat.isnan(number):635        return number636637    # Deal with extreme values for ndigits. For ndigits &gt; NDIGITS_MAX, x638    # always rounds to itself.  For ndigits &lt; NDIGITS_MIN, x always639    # rounds to +-0.0.640    if ndigits &gt; NDIGITS_MAX:641        return number642    elif ndigits &lt; NDIGITS_MIN:643        # return 0.0, but with sign of x644        return 0.0 * number645646    # finite x, and ndigits is not unreasonably large647    z = rfloat.round_double(number, ndigits)648    if rfloat.isinf(z):649        raise OverflowError650    return z``