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