在Qt中强制点而不是浮点的逗号 [英] Force point and not comma for floating point in Qt
本文介绍了在Qt中强制点而不是浮点的逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个非常基本的问题:如何在Qt中使用浮点数而不是逗号(我有一个法语版本的操作系统)?
$ b
解决方案
其他问题:可以用空格显示数千个分隔符的数字。 p>
QLocale loc = QLocale :: system(); // current locale
loc.setNumberOptions(QLocale :: c()。numberOptions()); //从C语言环境中借用数字选项
QLocale :: setDefault(loc); //设置为默认值
如果你想要所有的选项在C语言环境,可以简单地做
QLocale :: setDefault(QLocale :: c());关于您的第二个问题:Qt不支持自定义语言环境,但您可以尝试将数字选项设置为,说匈牙利的语言环境(应该产生1234和12 345.67 - 我没有自己尝试过) QLocale loc = QLocale ::系统(); // current locale
QLocale hungary(QLocale :: Hungarian);
loc.setNumberOptions(hungary.numberOptions()); //从匈牙利语语言环境中借用数字选项
QLocale :: setDefault(loc); //设置为默认
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 question :is it possible to display numbers with space for thousands separators?
解决方案 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
这篇关于在Qt中强制点而不是浮点的逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文