1
How can I use QLocate
to convert integer into standard Brazilian price form
(without rounding up the figures)?
Code:
QString n1 = "1.020,50";
QString n2 = "10,33";
int valor1 = n1.replace(".","").replace(",","").toInt();
int valor2 = n2.replace(".","").replace(",","").toInt();
int resultado_int = (valor1 + valor2);
qDebug() << resultado_int; //correto sem arredondar 100383
//converter
QLocale loc = QLocale::system();
QLocale brasil(QLocale::Portuguese);
loc.setNumberOptions(brasil.numberOptions());
QLocale::setDefault(loc);
qDebug() << brasil.toString(resultado_int); //erro return = "103.083"
But then what’s the problem. Try adding
11.020,50 + 10,33
returns11.030,8
and not11.030,83
.– Hy-brazil
I ran the code I posted and it’s coming back
"1.030,83"
.– Lucas Lima
is
11.020,50 + 10,33
with1.020,50 + 10,33
wheel without error.– Hy-brazil
Actually, I fixed the code. I think it’s right now. I mainly changed the
toString()
– Lucas Lima
Thank you very much, now it’s worked. :)
– Hy-brazil