this is my code:
from math import ceil
a = 25
a = float(a/10)
a = int(ceil(a))*10
print a
i get 20, but i want get 30 ,
the next is what i want get:
if开发者_Python百科 the a is 22 , i want get 20
if the a is 25 , i want get 30
if the a is 27 , i want get 30
if the a is 21 , i want get 20
so what can i do ,
thanks
You're looking for the round()
function:
print int(round(25, -1))
You can use the round() method
>>> num = 25
>>> round_num = int(round(num, -1))
>>> round_num
30
>>> num = 22
>>> round_num = int(round(num, -1))
>>> round_num
20
and so on.
精彩评论