아미(아름다운미소)

python 숫자 출력에서 천(1000) 단위마다 콤마를 출력 본문

랭귀지/PYTHON

python 숫자 출력에서 천(1000) 단위마다 콤마를 출력

유키공 2018. 11. 15. 09:00

python 숫자 출력에서 천(1000) 단위마다 콤마를 출력

1. format 지정 - 파이썬 2.7 이상
value = 123456789
print "{:,}".format(value)

2. locale모듈 사용 :
import locale
print locale.setlocale(locale.LC_ALL, 'en_US')
print locale.format("%d", 123456789, grouping=True)


Comments