Results 1 to 5 of 5

Thread: Number formatting

  1. #1
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Number formatting

    I know it doesn't take much to code something like this myself, but if Qt already has the functionality, it makes sense to use that rather than bloating my source code.

    64-bit integer such as: 17753210880. I want it displayed as: 17,753,210,880. Does Qt support this already or do I have to write my own method? In which case I'm not sure whether the best way is mathematically or using QString to insert the commas...

  2. #2
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: Number formatting

    I you want to display it, you'll need to convert it to QString.

    So, when you convert it to QString, insert the commas

  3. #3
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    507
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Number formatting

    Hi, maybe QLocale::toString helps.

    Ginsengelf

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Number formatting

    QLocale::toString sounds perfect. Seems it'll even decide on whether to use ',' or '.' depending on country.

  5. #5
    Join Date
    Apr 2009
    Posts
    46
    Thanks
    4
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Number formatting


Similar Threads

  1. Apparent error in QtCore/quuid.h
    By cwp500 in forum Qt Programming
    Replies: 11
    Last Post: 18th December 2008, 20:51
  2. Number formatting for file name construction
    By philwinder in forum Qt Programming
    Replies: 1
    Last Post: 14th May 2008, 10:57
  3. Line Number - QTextEdit...???
    By deepusrp in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2007, 16:34
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  5. get error number from qsqldatabase
    By mandal in forum Qt Programming
    Replies: 1
    Last Post: 19th January 2007, 10:20

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.