Format of float to QString conversion

c++, format, qstring, qt

Solution

Did you try QLocale::toString() already?

The following code should return the float with comma as decimal separator:

QLocale german(QLocale::German, QLocale::Germany);
QString s1 = german.toString(12.95, 'f');

Problem

I would like to convert a float to a QString but replacing the `.` by a `,`. For example, I want the float `12.95` to be converted to a QString that looks like `12,95`. I guess I can do it with something like: ``` QString().sprintf("%something", myFloat); ``` But how should I write instead of `%something`? Maybe I can do it like this: `QString::number(myFloat, 'f').replace(".", ",")` but it is not very pretty...

Original source