128
Comentário:
|
1135
|
Deleções são marcadas assim. | Adições são marcadas assim. |
Linha 4: | Linha 4: |
{{{ #!python import locale sal=2500.87 aumento=0.25 perc=10 vendas=4800.9 prejuizo=-3200 print "locale", "=>", locale.setlocale(locale.LC_ALL, "") print '------Formato numero Float------' print locale.format("%1.0f",sal,0) print locale.format("%1.2f",sal,0) print locale.format("%1.3f",sal,0) print locale.format("%1.2f",(sal-10000),0) print '------Formato numero Porc-------' print locale.format("%2.2f%%",(aumento * 100),0) print locale.format("%2.3f%%",(aumento * 100),0) print locale.format("%1.2f%%",(perc * 100),1) print locale.format("%1.3f%%",(perc * 100),1) print '------Formato moeda ------------' info=locale.localeconv() print info['currency_symbol'],locale.format("%1.2f",vendas,1) print info['currency_symbol'],locale.format("%1.3f",vendas,1) print info['currency_symbol'],locale.format("%1.2f",prejuizo,1) print info['currency_symbol'],locale.format("%1.3f",prejuizo,1) print 'Simbolo internacional da moeda no pais => ',info["int_curr_symbol"] }}} |
Neste exemplo usei o modulo locale para criar formatações de numeros e moedas no padrão do Brasil
Segue abaixo o codigo:
1 import locale
2
3 sal=2500.87
4 aumento=0.25
5 perc=10
6 vendas=4800.9
7 prejuizo=-3200
8 print "locale", "=>", locale.setlocale(locale.LC_ALL, "")
9
10 print '------Formato numero Float------'
11 print locale.format("%1.0f",sal,0)
12 print locale.format("%1.2f",sal,0)
13 print locale.format("%1.3f",sal,0)
14 print locale.format("%1.2f",(sal-10000),0)
15
16 print '------Formato numero Porc-------'
17 print locale.format("%2.2f%%",(aumento * 100),0)
18 print locale.format("%2.3f%%",(aumento * 100),0)
19 print locale.format("%1.2f%%",(perc * 100),1)
20 print locale.format("%1.3f%%",(perc * 100),1)
21
22 print '------Formato moeda ------------'
23 info=locale.localeconv()
24 print info['currency_symbol'],locale.format("%1.2f",vendas,1)
25 print info['currency_symbol'],locale.format("%1.3f",vendas,1)
26 print info['currency_symbol'],locale.format("%1.2f",prejuizo,1)
27 print info['currency_symbol'],locale.format("%1.3f",prejuizo,1)
28
29 print 'Simbolo internacional da moeda no pais => ',info["int_curr_symbol"]