# 3 examples of 'how to round to the nearest tenth in python' in Python

Every line of 'how to round to the nearest tenth in python' 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
``50def closest(number, ndigits=0, resolution=None):51    """Round a number defining the number of precision decimal digits and52    the resolution.5354    Examples55    --------5657    >>> closest(103.66778,)58    104.059    >>> closest(103.66778, ndigits=2)60    103.6761    >>> closest(103.66778, ndigits=2, resolution=5)62    105.063    >>> closest(103.66778, ndigits=2, resolution=0.5)64    103.565    >>> 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))``
``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))``
``8def round_to_ten(d):9  t = int(d//10)*1010  if t==180: return -18011  return t``