Solved How to convert numbers to local currency format?
-
-
@SGaist I did not do this.
Where in the code should I put this "import"?
I tried to put in the .pro file but it didn't work. QT did not recognize this command.
-
At the top of your .qml file as explained here in Qt's documentation.
-
@SGaist I forgot to say that I am programming in C ++. I think the .qml file is not accepted here, right?
-
@Alexandre-Camelo said in How to convert numbers to local currency format?:
I forgot to say that I am programming in C ++.
Your examples above ar qml, now you're telling us you're trying to compile qml code in C++??
-
@Christian-Ehrlicher Excuse me. My mistake. I'm new to QT.
I think I looked in the wrong part of the documentation.
The above example was copied from the QT documentation.
I am programming in C ++.
What is the method for converting numbers to local currency so that these numbers, even with currency formatting, can be used in mathematical expressions (sum, multiplication, etc.)?
-
Use QLocale
-
@Alexandre-Camelo said in How to convert numbers to local currency format?:
I am programming in C ++.
as @Christian-Ehrlicher say, you have to used QLocale, like this:
auto german = QLocale("de_DE"); double value = 1234.56; qDebug() << german.toString(value, 'f', 2);
-
@Alexandre-Camelo said in How to convert numbers to local currency format?:
I am trying to convert typed numbers in a line edit to local currency format.
double num = lineEdit->locale().toDouble(lineEdit->text());
-
@KroMignon Ok. It worked.
Thank you.
But I only have one more small question:
I read from the QT documentation that there is a way for QLocale to include the local currency symbol in the formatted number. Although I read, I couldn't understand how to do that.
After your tip, I was able to format the numbers to the local currency, but I'm concatenating the Brazilian currency symbol next to the number.
How can I enter the currency symbol through QLocale?
-
@Alexandre-Camelo said in How to convert numbers to local currency format?:
How can I enter the currency symbol through QLocale?
By taking a look at the documentation
-