Created
March 12, 2020 09:27
-
-
Save elmoiv/493fc3ea1d20ee3c721e41300cc5cebc to your computer and use it in GitHub Desktop.
[Python Tricks #3] Apply thousand separators to numbers.
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
# 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