10

我想知道如何在 int 或 string 中设置 ',' 逗号?例如,我已经得到了这个:

QString::number(object->number()) 

这将显示在 UI 上。

数字类似于123456789,如何设置字符串的格式123,456,789

4

5 回答 5

11

在http://doc.qt.io/qt-4.8/qlocale.html查看 QLocale 上的文档:

QLocale(QLocale::English).toString(123456789);
于 2013-01-16T08:03:07.317 回答
3

您正在调查QLocale::toString(int)

int i = 123456789;
QLocale l = QLocale::system();
QString s = l.toString(i);

笔记:

于 2013-01-16T08:04:39.533 回答
1

是肯定的!试试这个:

QLocale locale(QLocale::English);
QString string = locale.toString(123456789.21345, 'f');
于 2013-01-16T08:05:07.777 回答
0

也许:http : //www.qtcentre.org/threads/9822-Numbers-with-comma-format QString number = QLocale(QLocale::English).toString(123456789, 'f', 2); (我没有测试过)

于 2013-01-16T07:59:16.650 回答
0
double n = 123456789.12345;
QString string = QLocale(QLocale::English).toString(n, 'f', 2);

这对我有用。

于 2021-03-17T01:21:12.797 回答