Force point and not comma for floating point in Qt

后端 未结 1 957
死守一世寂寞
死守一世寂寞 2021-01-15 23:02

I have a very basic question: how can I enforce the use of points in floating-point numbers instead of a comma (I have a french version of my OS) in Qt?

Other questi

相关标签:
1条回答
  • 2021-01-15 23:48

    Try this:

    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 of 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 options to, say, Hungary's locale (it should produce 1234 and 12 345.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
    
    0 讨论(0)
提交回复
热议问题