Created
June 27, 2012 11:43
-
-
Save ikegami-yukino/3003536 to your computer and use it in GitHub Desktop.
キャストしないでInt to Ascii
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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