Skip to content

Instantly share code, notes, and snippets.

@elmoiv
Created March 12, 2020 09:27
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 elmoiv/493fc3ea1d20ee3c721e41300cc5cebc to your computer and use it in GitHub Desktop.
Save elmoiv/493fc3ea1d20ee3c721e41300cc5cebc to your computer and use it in GitHub Desktop.
[Python Tricks #3] Apply thousand separators to numbers.
# Normal
## Python 2.7
n = input()
'{:,}'.format(n)
## Python 3.6
n = int(input())
f'{n:,}'
# With rounding
## Python 2.7
n = input()
'{:,.2f}'.format(n)
## Python 3.6
n = int(input())
f'{n:,.2f}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment