Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How does qt convert qstring into float?
How does qt convert qstring into float?
When programming with Qt Creator, it is inevitable to use it to convert float type into QString type. Here are all my methods:

1. It is very simple to convert QString type to float type.

QString data;

float num = data . to float();

This is easy to achieve.

2. But how do you convert a float type into a QString type?

It is difficult to find the encapsulated conversion function by looking at the API.

You can try the following transcoding:

Floating point number =1.222;

QString data = QString("float is% 1 "). arg(num);

The output result is: float is 1.222.

If only float is converted to a numerical value, use the following:

QString data = QString("% 1 ")。 arg(num);