Results 1 to 3 of 3

Thread: Numbers with comma format

  1. #1
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Numbers with comma format

    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

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Numbers with comma format

    Not tested:
    Qt Code:
    1. QString number = "....";
    2. int i = number.lastIndexOf('.');
    3. if(i >0)
    4. {
    5. i -= 3;
    6. while(i > 0)
    7. {
    8. number.insert(i, ',');
    9. i -= 3;
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to marcel for this useful post:

    baray98 (25th October 2007)

  4. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Numbers with comma format

    Try
    Qt Code:
    1. QString number = QLocale(QLocale::English).toString(123456789, 'f', 2);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  5. The following 3 users say thank you to jpn for this useful post:

    baray98 (25th October 2007), gfunk (7th December 2007), iskenderoguz (6th February 2016)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.