PDA

View Full Version : int to QString with thousands separator



klaus1111
5th January 2006, 14:15
Hi,
is there a Qt-way to convert an integer (for example a file size) into a string with dots between the digits?

like this: 1.234.567

Klaus

munna
5th January 2006, 14:20
you can use QString::number() to convert the int into a QString and then according to the length of the string you can insert '.' where ever you want.

wysota
5th January 2006, 14:26
Hi,
is there a Qt-way to convert an integer (for example a file size) into a string with dots between the digits?

like this: 1.234.567


If you use QLocale::toString with properly set locale, you'll get your dotted output :)

whoops.slo
5th January 2006, 14:48
Of course you can use this code...


QString word = QString::number(num, 10);
int w_size = word.size();
if (w_size > 3) {
word.insert(word.size() - 3, ".");
}
if (w_size > 6) {
word.insert(word.size() - 7, ".");
}

Regards,
Luka

yop
6th January 2006, 22:35
If you use QLocale::toString with properly set locale, you'll get your dotted output :)Or any other localized output in the world. I've used it to display prices and it is a true timesaver. I think it's available only after Qt 3.3.2.

wysota
6th January 2006, 22:56
Eeem... 3.3.0 :) x.y.z versions are just bug fixes, no new features are added, so it must have been a "0" release. But the point here is that with using QLocale you can have output from a different locale than the rest of the application uses.

yop
6th January 2006, 23:06
Eeem... 3.3.0 :) x.y.z versions are just bug fixes, no new features are added, so it must have been a "0" release. But the point here is that with using QLocale you can have output from a different locale than the rest of the application uses.Yes fast typing played it's role :o. Just confirmed no QLocale in 3.2.x, it's a 3.3.x addition