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...
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');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With