我在想如何在int或字符串中設置','逗號? 舉例來說,我已經得到了這個:在字符串中添加逗號
QString::number(object->number())
將在UI中顯示。
而且這個數字有點像123456789
,我怎樣才能設置字符串的格式是123,456,789
?
我在想如何在int或字符串中設置','逗號? 舉例來說,我已經得到了這個:在字符串中添加逗號
QString::number(object->number())
將在UI中顯示。
而且這個數字有點像123456789
,我怎樣才能設置字符串的格式是123,456,789
?
結帳在http://doc.qt.io/qt-4.8/qlocale.html上QLocale文檔:
QLocale(QLocale::English).toString(123456789);
也許:http://www.qtcentre.org/threads/9822-Numbers-with-comma-format QString number = QLocale(QLocale :: English).toString(123456789,'f',2); (我沒有測試)
您正在尋找進入QLocale::toString(int)
int i = 123456789;
QLocale l = QLocale::system();
QString s = l.toString(i);
注:
是的,當然!試試這個:
QLocale locale(QLocale::English);
QString string = locale.toString(123456789.21345, 'f');
這一個不爲我編譯。 QLocale :: toString的重載是用於float/double的,並且在向其傳遞整數時不明確。 – goji
這不像特洛伊說的那樣 – user1345821