开发者

how to get 30 if a is 25 using python

开发者 https://www.devze.com 2023-02-20 05:14 出处:网络
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 ,

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消