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. Display double number without exponential format
Forum Updated to NodeBB v4.3 + New Features

Display double number without exponential format

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 6.6k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    snaksa
    wrote on last edited by
    #1

    Hello! Let's say that I have a double number: 1679616. When I try to set text to label, the number is shown as 1.67962e+06. Is there a way so that the number can be shown as it is without exponential format? If I use: QString::number(result, 'f', 2) to cast the number to string, everything is ok, but what if the number has more than two digits after that point? I know I can set it to be 10 for example, but you know that this is not the right thing that I want to do. I want if the number is 82348.12323 to be shown 82348.12323. If it is 234.2, I want just one digit after the point.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      Did you try this here?
      @
      QString::number(result,'f',-1);
      @

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • S Offline
        S Offline
        snaksa
        wrote on last edited by
        #3

        Thanks for the reply. I tried it but it shows six digits after the decimal point. Just like the default parameter if I haven't typed anything as third parameter.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          [quote]
          Argument Formats
          In member functions where an argument format can be specified (e.g., arg(), number()), the argument format can be one of the following:
          Format Meaning
          e format as [-]9.9e[+|-]999
          E format as [-]9.9E[+|-]999
          f format as [-]9.9
          g use e or f format, whichever is the most concise
          G use E or f format, whichever is the most concise
          A precision is also specified with the argument format. For the 'e', 'E', and 'f' formats, the precision represents the number of digits after the decimal point. For the 'g' and 'G' formats, the precision represents the maximum number of significant digits (trailing zeroes are omitted).
          [/quote]
          The last sentence of section in "QString description":http://qt-project.org/doc/qt-5/QString.html#argument-formats says it. You should just use 'g' or 'G'.

          [edit, koahnig]

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          0

          • Login

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