Created
May 5, 2016 00:23
-
-
Save myano/67c81f691e2b0eccdb868738041262ad to your computer and use it in GitHub Desktop.
Format a really long number with commas
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
def formatnumber(n): | |
"""Format a number with beautiful commas.""" | |
parts = list(str(n)) | |
for i in range((len(parts) - 3), 0, -3): | |
parts.insert(i, ',') | |
return ''.join(parts) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment