help with Qlocale and format currency brazil

-1

In c ++ I used to convert an integer value to the Brazilian currency format as follows:

QLocale loc = QLocale::system();
QLocale brasil(QLocale::Portuguese);
loc.setNumberOptions(brasil.numberOptions());
QLocale::setDefault(loc);

cout << brasil.toString(orcamentoDisponivel * 0.01, 'f', 2).toStdString();

In PyQt, I did this:

# -*- coding: utf-8 -*-
from PyQt4 import QtCore
orcamentoDisponivel = 225710000
loc = QtCore.QLocale.system().name()
lang = QtCore.QLocale(loc) # ou substituir loc por 'pt_BR' 
print lang.toString(int(orcamentoDisponivel * 0.01))

The problem is that while in c ++ I had output, for example: 2,257,100.00 (correct value for my case)

In python I have output: 225,710,000

Could anyone help me solve this? Thanks!

    
asked by anonymous 28.01.2017 / 21:34

1 answer

1

Resolved:

#https://docs.python.org/2/library/locale.html
import locale
locale.setlocale(locale.LC_ALL, '') 
print locale.format('%.2f', (value * 0.01), True)

or

#http://stackoverflow.com/questions/41917083/qlocale-and-brazil-currency-format    
from PyQt4 import QtCore
value = 225710000
lang = QtCore.QLocale('pt_BR')
print lang.toString(value * 0.01, 'f', 2)
    
29.01.2017 / 20:42