공부
[Python] Format number (#,###) (python comma)
승가비
2020. 4. 3. 00:26
728x90
# Locale unaware
'{:,}'.format(value) # For Python ≥2.7
f'{value:,}' # For Python ≥3.6
Locale aware
# import locale
locale.setlocale(locale.LC_ALL, '') # Use '' for auto, or force e.g. to 'en_US.UTF-8'
'{:n}'.format(value) # For Python ≥2.7
f'{value:n}' # For Python ≥3.6
https://stackoverflow.com/questions/1823058/how-to-print-number-with-commas-as-thousands-separators
How to print number with commas as thousands separators?
I am trying to print an integer in Python 2.6.1 with commas as thousands separators. For example, I want to show the number 1234567 as 1,234,567. How would I go about doing this? I have seen many
stackoverflow.com
728x90