Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to convert numbers to local currency format?

How to convert numbers to local currency format?

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 5 Posters 2.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    Based on the Number type documentation, do you have

    import QtQml 2.14
    

    in your script ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    Alexandre CameloA 1 Reply Last reply
    2
    • SGaistS SGaist

      Hi,

      Based on the Number type documentation, do you have

      import QtQml 2.14
      

      in your script ?

      Alexandre CameloA Offline
      Alexandre CameloA Offline
      Alexandre Camelo
      wrote on last edited by
      #3

      @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.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #4

        At the top of your .qml file as explained here in Qt's documentation.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        Alexandre CameloA 1 Reply Last reply
        2
        • SGaistS SGaist

          At the top of your .qml file as explained here in Qt's documentation.

          Alexandre CameloA Offline
          Alexandre CameloA Offline
          Alexandre Camelo
          wrote on last edited by
          #5

          @SGaist I forgot to say that I am programming in C ++. I think the .qml file is not accepted here, right?

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #6

            @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++??

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            Alexandre CameloA 1 Reply Last reply
            2
            • Christian EhrlicherC Christian Ehrlicher

              @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++??

              Alexandre CameloA Offline
              Alexandre CameloA Offline
              Alexandre Camelo
              wrote on last edited by
              #7

              @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.)?

              KroMignonK 1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #8

                Use QLocale

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                5
                • Alexandre CameloA Alexandre Camelo

                  @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.)?

                  KroMignonK Offline
                  KroMignonK Offline
                  KroMignon
                  wrote on last edited by VRonin
                  #9

                  @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);
                  

                  It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                  Alexandre CameloA 1 Reply Last reply
                  3
                  • Alexandre CameloA Alexandre Camelo

                    Hello friends.

                    I am trying to convert typed numbers in a line edit to local currency format.

                    I tried as in the QT documentation, but it didn't work. The compiler does not recognize NUMBER QMT TYPE.

                    It also does not recognize the variable type VAR, as shown in the example QT documentation.

                    I copied below what is in the documentation:

                    Method Documentation

                    string fromLocaleString(locale, number)

                    Returns a Number by parsing number using the conventions of the supplied locale.
                    If locale is not supplied the default locale will be used.
                    For example, using the German locale:

                    Method Documentation

                    string fromLocaleString(locale, number)

                    Returns a Number by parsing number using the conventions of the supplied locale.
                    If locale is not supplied the default locale will be used.
                    For example, using the German locale:

                    <code>
                    var german = Qt.locale("de_DE");
                    var d;
                    d = Number.fromLocaleString(german, "1234,56") // d == 1234.56
                    d = Number.fromLocaleString(german, "1.234,56") // d == 1234.56
                    d = Number.fromLocaleString(german, "1234.56") // throws exception
                    d = Number.fromLocaleString(german, "1.234") // d == 1234.0

                    <code>

                    Do I need to do some INCLUDE? Is this method obsolete? What is the most practical method to do this?

                    VRoninV Offline
                    VRoninV Offline
                    VRonin
                    wrote on last edited by
                    #10

                    @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());

                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                    ~Napoleon Bonaparte

                    On a crusade to banish setIndexWidget() from the holy land of Qt

                    1 Reply Last reply
                    3
                    • KroMignonK KroMignon

                      @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 CameloA Offline
                      Alexandre CameloA Offline
                      Alexandre Camelo
                      wrote on last edited by
                      #11

                      @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?

                      1 Reply Last reply
                      0
                      • Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #12

                        @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

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        Alexandre CameloA 1 Reply Last reply
                        2
                        • Christian EhrlicherC Christian Ehrlicher

                          @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

                          Alexandre CameloA Offline
                          Alexandre CameloA Offline
                          Alexandre Camelo
                          wrote on last edited by
                          #13

                          @Christian-Ehrlicher Thank you, Christian.

                          Your tips were enough for me to solve the problem!

                          :-)

                          1 Reply Last reply
                          1

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved