Flower in my dev/Python

<PYTHON>[locale]

꽃선생 2015. 7. 9. 10:52

[locale]

 

문자열을 표현할 때,

 

돈을 표현할 일이 생긴다.

 

그럼 세자리마다 [,]를 찍어주어야 하는데

 

그때 사용한다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import locale
 
locale.setlocale(locale.LC_ALL, '')
 
= 12039238273592834.123123
 
= locale.format('%.2f', n, 1)
 
print s
 
= 1209312037141.1231254
 
= locale.format('%.4f', n, 1)
 
print s
 
= 12312412512.12352
 
= locale.format('%.3f', n, 1)
 
print s
 
= 12312412512.12352
 
= locale.format('%.2f', n, 1)
 
print s
 
cs

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

*주의

 

n = 12039238273592834.123123

 

뒤에 소수점뒤에서 00으로 표현이 된다.

 

15자리를 넘어갔기 때문이다.

 

n = 120392382735928.123123

 

2자리를 지우고 테스트하면 표현되는 것을 확인 할 수 있다.