Force, not comma for floating point in Qt

I have a very simple question: How can I force the use of dots in floating point numbers instead of commas (I have a French version of my OS) in Qt?

Another question: is it possible to display numbers with thousands separator spaces?

+1


source to share


1 answer


Try the following:

QLocale loc = QLocale::system(); // current locale
loc.setNumberOptions(QLocale::c().numberOptions()); // borrow number options from the "C" locale
QLocale::setDefault(loc); // set as default

      

If you want all the options as in the "C" locale, you can simply do



QLocale::setDefault(QLocale::c());

      

Regarding your second question: Qt does not support custom locales, but you can try setting the number parameters in, say, Hungary (it should produce 1234 and 12345.67 - I haven't tried it myself)

QLocale loc = QLocale::system(); // current locale
QLocale hungary(QLocale::Hungarian);
loc.setNumberOptions(hungary.numberOptions()); // borrow number options from the Hungarian locale
QLocale::setDefault(loc); // set as default

      

+4


source







All Articles