How can I round to two places - not decimal places?
ex.
input: 2.6759, 3.5632, 30.8736, 42.8927
output: 2.7, 3.6, 31, 43
How can I round to two places - not decimal places?
ex.
input: 2.6759, 3.5632, 30.8736, 42.8927
output: 2.7, 3.6, 31, 43
import math
def roundx(v):
scale = int(math.log10(v))
x = int(v * 10**(1-scale) + 0.5) * 10**(scale-1)
return x
for v in (2.6759,3.5632,30.8736,42.8927):
print(roundx(v))
Output:
2.7
3.6
31
43