10 examples of 'python round up' in Python

Every line of 'python round up' 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
4def round_down(v):
5 return (int(v[0]), int(v[1]))
17def round_up(x, base=1):
18 return int(base * round(float(x)/base))
71def roundup(n, q):
72 import math
73 return int(math.ceil(float(n) / float(q)) * q)
147def round3(x):
148 return int(x * 1000) / 1000.0
631def 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
312def p_round(n, precision=5):
313 precision = int(precision)
314 return int(round(n / float(precision))) * precision
80def roundup(characters):
81 """
82 Prevent '=' at the end of base64 encoded strings.
83
84 This is done by rounding up the number of characters.
85
86 Arguments:
87 characters: The number of requested (8-bit) characters.
88
89 Returns:
90 The revised number.
91 """
92 bits = characters * 6
93 upto = 24
94 rem = bits % upto
95 if rem:
96 bits += (upto - rem)
97 return int(bits / 8)
4def roundInt(a): return int(a+0.5)
27def roundint(v):
28 return int(round(v))
130def roundup(val, width):
131 """roundup a value to N x width-bits"""
132 x = (width >> 3) - 1
133 return (val + x) & ~x

Related snippets