April 16, 2012

fs_tigre fs_tigre
Ant Farmer
146 posts

How can I change my output

 

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.

  1. float yields = 1 / 11850;
  2. 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

2 replies

April 16, 2012

Andre Andre
Area 51 Engineer
6031 posts

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.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

April 16, 2012

fs_tigre fs_tigre
Ant Farmer
146 posts

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.

 
  ‹‹ [Solved] Closing a dialog with a timer.      [SOLVED] Help in Creating Indexed8 image from a buffer ››

You must log in to post a reply. Not a member yet? Register here!