Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format of float to QString conversion

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

like image 289
Maxbester Avatar asked Feb 17 '23 16:02

Maxbester


1 Answers

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');
like image 190
cloose Avatar answered Feb 24 '23 15:02

cloose