Qt-自定义小数点和千位分隔符 [英] Qt - custom decimal point and thousand separator

查看:619
本文介绍了Qt-自定义小数点和千位分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将具有自定义小数点和千位分隔符的数字(双精度)转换为字符串?

How can I convert a number (double) to string, with custom decimal point and thousand separator chars?

我见过QLocale,但是我不想选择本地化国家/地区,而是指定自己的小数点和千位分隔符.

I've seen QLocale, but I don't want to choose the localization country, but rather specify my own decimal point and thousand separator chars.

谢谢

推荐答案

Qt不支持自定义语言环境.但是只处理组字符和小数点字符是微不足道的:

Qt doesn't support custom locale. But to deal with just group and decimal point characters is trivial:

const QLocale & cLocale = QLocale::c();
QString ss = cLocale.toString(yourDoubleNumber, 'f');
ss.replace(cLocale.groupSeparator(), yourGroupChar);
ss.replace(cLocale.decimalPoint(), yourDecimalPointChar);

顺便说一句,spbots的问题不是无关紧要的.关于目标的更多细节总是有帮助的,它可能会导致采用不同的方法来更好地为您服务.

BTW, spbots' question is not irrelevant. More detail about the goal always helps and it could lead to different approach that may serve you better.

这篇关于Qt-自定义小数点和千位分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆