How to make 1.123456 , 1.123?
-
do you always want the string to have 5 characters or do you want to always have 3 chars after the comma? Just asking because 123456.56789 with your code would become 12345.
-
the number is noway to be bigger than 9.99999
so i want always from it to have 5 characters..
-
And do you need to round the last digit, or just cut it off?
-
cut it off.. as said
@float number= 3.333333 // here it could be 1/ 1.3333333/ 1.33 .. What i want is always to show 5 characters.. so 1->1.000 / 1.3333333->1.333 / 1.33->1.330@
-
Why not just use
@
QString::number(value,'f',5);
@
to force 5 decimal places? -
Hello.
Just use
@
QString str = QString::number(/your number to show/,'g',5);while (str .length() < 5) {
str .append('0');
}ui->lcdNumber->display(str);
@ -
AFAIK trailing zeros will be cut off
[quote author="mlong" date="1348759875"]Why not just use
@
QString::number(value,'f',5);
@
to force 5 decimal places?
[/quote]
Edit: my fault, it won't. -
[quote author="mlong" date="1348759875"]Why not just use
@
QString::number(value,'f',5);
@
to force 5 decimal places?
[/quote]i said 3 decimal places.. so 5->3 will do exactly what i want.. thank you a lot! i really need to read my C++ book but i don't have time cause of my studies.. next year :)
-
Leon: So you plan to nag us here for one more year because you have no time to learn something due to studies? I am not sure that is what is intended with this whole university-thing:-)
-
Or you can use ansi/iso c++ (so called: manipulators) too:
@
cout.precision(4) ;
cout.width(10);
cout << 10.12345 << "\n"; // displays 10.12
cout.fill('*');
cout.width(10);
cout << 10.12345 << "\n"; // displays *****10.12
@
and so on...