在字符串中添加逗号
Add comma's in string
我想知道如何在int或字符串中设置","逗号?例如,我已经得到了这个:
QString::number(object->number())
这将显示在UI上。
这个数字有点像123456789
,我如何设置字符串为123,456,789
的格式?
在QLocale上签出文档http://doc.qt.io/qt-4.8/qlocale.html:
QLocale(QLocale::English).toString(123456789);
您正在研究QLocale::toString(int(
int i = 123456789;
QLocale l = QLocale::system();
QString s = l.toString(i);
注:
- 不要使用"逗号",在每个地区(语言、国家(这是不同的。看见http://www.gnu.org/software/gettext/manual/gettext.html#Aspects以获取更多示例
- 如果您使用QString::number((,您将获得一个局部相关的表示
可能:http://www.qtcentre.org/threads/9822-Numbers-with-comma-formatQString number=QLocale(QLocale::English(.toString(123456789,'f',2(;(我还没有测试(
当然!试试这个:
QLocale locale(QLocale::English);
QString string = locale.toString(123456789.21345, 'f');
double n = 123456789.12345;
QString string = QLocale(QLocale::English).toString(n, 'f', 2);
这对我很有效。
相关文章:
- 重载加法运算符(使用函数向对象添加字符串)
- 在不使用内置库函数的情况下添加字符串,我做错了什么?
- 添加字符串和文字(C++)
- 添加字符串类型的类成员会导致调用基类函数而不是子函数
- 添加字符串向量和不同数据类型向量的映射
- 在链接列表中添加字符串的简单方法
- 列表框中的添加字符串 (MFC)
- 添加字符串和文字,顺序如何影响是否可以正确添加字符串
- 向矢量集添加字符串时出现问题<string><>
- 在C++中添加字符串和文字时出现问题
- free():添加字符串时指针无效
- 为什么通过添加字符串文字和char初始化时,为什么不打印字符串
- 矢量尝试添加字符串时会崩溃
- 在数组 C++ 中添加字符串
- 如何添加字符串
- 从向量中删除和添加字符串
- 添加字符串和列表到c++中的映射
- 添加字符串变量后的两个不同的双值
- 为什么我的非所有者绘制的列表框在添加字符串后会出现绘图问题
- 当试图向结构中添加字符串时,程序中断