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.
248 def nearest(n): 249 """ 250 round up or down to nearest int returning an int 251 252 Used for selecting the nearest pixel position. 253 254 WARNING, this method is vectorised to handle a numpy array by NumpyImage 255 256 :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: return 260 n=float(n) # make sure n is a float 261 return int(round(n,0))
71 def roundup(n, q): 72 import math 73 return int(math.ceil(float(n) / float(q)) * q)
238 def round2 (n): 239 """ Get nearest power of two superior to n """ 240 f = 1 241 while f
312 def p_round(n, precision=5): 313 precision = int(precision) 314 return int(round(n / float(precision))) * precision
4 def round_down(v): 5 return (int(v[0]), int(v[1]))
50 def closest(number, ndigits=0, resolution=None): 51 """Round a number defining the number of precision decimal digits and 52 the resolution. 53 54 Examples 55 -------- 56 57 >>> closest(103.66778,) 58 104.0 59 >>> closest(103.66778, ndigits=2) 60 103.67 61 >>> closest(103.66778, ndigits=2, resolution=5) 62 105.0 63 >>> closest(103.66778, ndigits=2, resolution=0.5) 64 103.5 65 >>> closest(103.66778, ndigits=2, resolution=0.25) 66 103.75 67 """ 68 num = round(number, ndigits) 69 return (num if resolution is None else 70 round((num // resolution * resolution + 71 round((num % resolution) / float(resolution), 0) * 72 resolution), ndigits))
17 def round_up(x, base=1): 18 return int(base * round(float(x)/base))
576 def _round_frac(x, precision): 577 """ 578 Round the fractional part of the given number 579 """ 580 if not np.isfinite(x) or x == 0: 581 return x 582 else: 583 frac, whole = np.modf(x) 584 if whole == 0: 585 digits = -int(np.floor(np.log10(abs(frac)))) - 1 + precision 586 else: 587 digits = precision 588 return np.around(x, digits)
631 def rpy_round(number, ndigits): 632 # Algorithm copied directly from CPython 633 634 if number == 0 or rfloat.isinf(number) or rfloat.isnan(number): 635 return number 636 637 # Deal with extreme values for ndigits. For ndigits > NDIGITS_MAX, x 638 # always rounds to itself. For ndigits < NDIGITS_MIN, x always 639 # rounds to +-0.0. 640 if ndigits > NDIGITS_MAX: 641 return number 642 elif ndigits < NDIGITS_MIN: 643 # return 0.0, but with sign of x 644 return 0.0 * number 645 646 # finite x, and ndigits is not unreasonably large 647 z = rfloat.round_double(number, ndigits) 648 if rfloat.isinf(z): 649 raise OverflowError 650 return z