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 can I change my output
Forum Updated to NodeBB v4.3 + New Features

How can I change my output

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.5k 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.
  • F Offline
    F Offline
    fs_tigre
    wrote on 16 Apr 2012, 12:49 last edited by
    #1

    Hi,

    I don't know if this is a math question but you guys probably know what may be the problem.

    What I have is label showing a number divided by 1, the problem is that I'm getting a wired number when I do the following division.

    @float yields = 1 / 11850;
    ui->label_Yields->setText(QString::number(yields));@

    I get 8.43882e-05 but when I used my calculator I get 0.00008439 which is what I one. In fact I tried this in two different calculators and one of them actually gave me the same result as in Qt 8.43882e-05 and the other one gives me 0.00008439.

    Any idea how can I make Qt to generate 0.00008439 when I divide 1 / 11850?

    Thanks a lot

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on 16 Apr 2012, 13:15 last edited by
      #2

      First of all, you should realize that both these numbers are in fact the same number. They are just represented in a different way. The version with the 'e' is actually more precise than the version you want (it has more significant digits). Did you try the documentation for the QString::number() method? One of the overloads of that method takes a format argument. You should experiment with that.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fs_tigre
        wrote on 16 Apr 2012, 13:52 last edited by
        #3

        Got it.

        ui->label_Yields->setText(QString::number(yields, 'f', 8));

        I actually tried this before but I was missing the quotes.

        Thank you for pushing me to reread the docs, believe me I'm getting better on trying to find info using the documentation.

        Thanks a lot for your help.

        1 Reply Last reply
        0

        1/3

        16 Apr 2012, 12:49

        • Login

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