Skip to content

Instantly share code, notes, and snippets.

@ikegami-yukino
Created June 27, 2012 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikegami-yukino/3003536 to your computer and use it in GitHub Desktop.
Save ikegami-yukino/3003536 to your computer and use it in GitHub Desktop.
キャストしないでInt to Ascii
# -*- coding: utf-8 -*-
MAX_DIGIT = 10 # 最大桁数(intなら10桁)
NUMS = ['0','1','2','3','4','5','6','7','8','9']
def itoa(num):
result = ''
previous = 0
for i in range(MAX_DIGIT,-1,-1):
temp = num / (10**i)
if temp > 0:
result += NUMS[temp - previous *10]
previous = temp
return result
if __name__ == '__main__':
print itoa(102340)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment