PDA

View Full Version : Numbers with comma format



baray98
25th October 2007, 20:02
Hi Guys,

I have a number (double) in QString and i want to show a comma on every 3 digit for my user . can I do it easily in QString manipulation stuff .. please give me a hint

example

given a number 123456789.00 I want to show it as 123,456,789.00

baray98

marcel
25th October 2007, 20:44
Not tested:


QString number = "....";
int i = number.lastIndexOf('.');
if(i >0)
{
i -= 3;
while(i > 0)
{
number.insert(i, ',');
i -= 3;
}
}

jpn
25th October 2007, 20:45
Try

QString number = QLocale(QLocale::English).toString(123456789, 'f', 2);