How do I find the next multiple of 10 of any integer?

后端 未结 12 1093
Happy的楠姐
Happy的楠姐 2020-12-08 04:15

Dynamic integer will be any number from 0 to 150.

i.e. - number returns 41, need to return 50. If number is 10 need to return 10. Number is 1 need to return 10.

12条回答
  •  伪装坚强ぢ
    2020-12-08 04:36

    You could do the number mod 10. Then take that result subtract it from ten. Then add that result to the original.

    if N%10 != 0  #added to account for multiples of ten 
      a=N%10
      N+=10-a
    

提交回复
热议问题