Linux 上大货币(或数字)的 Qt 区域设置格式
我正在尝试将数字格式化为货币但遇到问题。我尝试过默认区域设置和特定区域设置(如下所示)。尽管如此,该数字仍采用科学记数法格式。
QLocale::setDefault( QLocale(QLocale::English, QLocale::UnitedStates) );
reportCost->setText( QString("$%L1").arg( cost ) );
问题是,一旦我达到数百万,我就会得到像 $1.6473e6
这样的数字,而不是 $1,647,312
。我该如何解决这个问题?
另外,在 Qt 中真的没有办法格式化货币,比如定位符号和正确的负表示吗?
我现在无法在 Windows 上进行测试,所以我不知道这是否是 Linux 特定的。
I am trying to format a number as a currency and having problems. I've tried with both the default locale and a specific one (like below). The number is formatted in scientific notation nonetheless.
QLocale::setDefault( QLocale(QLocale::English, QLocale::UnitedStates) );
reportCost->setText( QString("$%L1").arg( cost ) );
The trouble is that as soon as I hit millions I get numbers like $1.6473e6
rather than $1,647,312
. How can I fix this?
Also,is there really no way to format a currency at all in Qt, like positioning the symbol and proper negative representation?
I cannot test on Windows right now so I don't know if this is Linux specific.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,
QLocale
的当前实现在许多方面都存在不足。请参阅“QLocale:这是关于时间(和日期、语言,以及……)” 来解释未来的发展方向。目前,一个快速而肮脏的解决方案是:
如果您需要真正本地化,则 ICU 库可能会有所帮助。
Unfortunately, the current implementation of
QLocale
falls short in a lot of these areas. See "QLocale: It’s about time (and dates, and languages, and …)" for an explanation of where this is headed in the future.For now, a quick-and-dirty solution would be:
If you need real localization, the ICU libraries might be helpful.
我知道这是一个老问题,但值得向任何偶然发现这个问题的人指出,在 Qt 4.8 及更高版本中,首先要尝试的应该是
QLocale::toCurrencyString(...)
I know that this is an old question, but it's worth pointing out to anyone who stumbles across this that in Qt 4.8 and above, the first thing to try should be
QLocale::toCurrencyString(...)