Qt - Converting float to QString

This seems like it should be very simple, but I'm going through the docs and not seeing anything. I just need to convert a number that is represented as a float object into a QString object. I know there is the function QString::number() that can be used for other types like int and double, like so: int a = 1; QString b = QString::number(a);

...however this doesn't seem to work for float. Perhaps there is some way where it is converted first from float to another type, and then from that type to QString? If anyone has any ideas I'd appreciate it. Thanks!

Answers


float will auto-promote to double when needed

float pi = 3.14; 
QString b = QString::number(pi);

should work

otherwise you can use setNum:

float pi = 3.14; 
QString b;
b.setNum(pi);

Need Your Help

Which operations preserve RDD order?

apache-spark rdd

RDD has a meaningful (as opposed to some random order imposed by the storage model) order if it was processed by sortBy(), as explained in this reply.

No entity found for query Exception

java jpa jboss ejb

I am executing the following lines: