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 float64 to QString
Qt 6.11 is out! See what's new in the release blog

How to convert float64 to QString

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 4 Posters 5.0k 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.
  • R Offline
    R Offline
    rockon209
    wrote on last edited by
    #1

    Hello Everyone,

    How i can convert float64 to QString. I am getting a variable value from a function with float64 type and i want to display it in QTextEdit. How I can do it. Thanks in advance.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      QString floatToString = textEdit->locale().toString(floatValue,'f');

      "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
      • R Offline
        R Offline
        rockon209
        wrote on last edited by rockon209
        #3

        @VRonin
        I want to dsiplay it in QTextedit, dont want to set the value tof textedit to QString
        for example
        float64 value = 2.33

        QTextEdit *textbox = new QTextEdit;
        textbox->setText(value)

        jsulmJ VRoninV 2 Replies Last reply
        0
        • R rockon209

          @VRonin
          I want to dsiplay it in QTextedit, dont want to set the value tof textedit to QString
          for example
          float64 value = 2.33

          QTextEdit *textbox = new QTextEdit;
          textbox->setText(value)

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by jsulm
          #4

          @rockon209

          QString floatToString = QLocale::system().toString(floatValue,'f');
          textbox->setText(floatToString);
          

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • R Offline
            R Offline
            rockon209
            wrote on last edited by
            #5

            @VRonin I am getting the following error
            error: no matching function for call to 'QLocale::toString(float64 [1], char)'
            QString floatToString = QLocale::system().toString(data1,'f');

            jsulmJ 1 Reply Last reply
            0
            • R rockon209

              @VRonin I am getting the following error
              error: no matching function for call to 'QLocale::toString(float64 [1], char)'
              QString floatToString = QLocale::system().toString(data1,'f');

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @rockon209 Why do you use float64 instead of float or double?
              If you want to use float 64 then cast it to float or double first.
              And toString isn't a static method - you need a QLocale instance to use it.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • beeckscheB Offline
                beeckscheB Offline
                beecksche
                wrote on last edited by beecksche
                #7

                If you mean float64 is equal to double, I would use the static function QString::number.

                double value = 1.234567:
                QString num = QString::number(value);
                
                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  rockon209
                  wrote on last edited by
                  #8

                  @jsulm @beecksche
                  I am getting the value from a function and that function gives float64 value as return. I thought about that but dont know how to cast float64 to float. If you know it please let me know.

                  jsulmJ 1 Reply Last reply
                  0
                  • R rockon209

                    @jsulm @beecksche
                    I am getting the value from a function and that function gives float64 value as return. I thought about that but dont know how to cast float64 to float. If you know it please let me know.

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @rockon209

                    double temp = static_cast<double>(value);
                    

                    use double to make sure it can represent all values a float64 can.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    4
                    • R Offline
                      R Offline
                      rockon209
                      wrote on last edited by
                      #10
                      This post is deleted!
                      1 Reply Last reply
                      0
                      • R rockon209

                        @VRonin
                        I want to dsiplay it in QTextedit, dont want to set the value tof textedit to QString
                        for example
                        float64 value = 2.33

                        QTextEdit *textbox = new QTextEdit;
                        textbox->setText(value)

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

                        @rockon209 said in How to convert float64 to QString:

                        @VRonin
                        I want to dsiplay it in QTextedit, dont want to set the value tof textedit to QString

                        That's not what I'm doing there

                        you can even combine.textEdit->setText(textEdit->locale().toString(floatValue,'f'));

                        "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
                        2

                        • Login

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