Results 1 to 20 of 22

Thread: Number formats 00.00

Hybrid View

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

    Default Re: Number formats 00.00

    Perhaps QString::arg() with fill char '0'?
    J-P Nurmi

  2. #2
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Qt products
    Qt3 Qt4
    Platforms
    Windows
    Thanks
    7
    Thanked 25 Times in 24 Posts

    Default Re: Number formats 00.00

    Try this:
    QString msg = QString("%1").arg(number);
    msg = msg.leftJustified(msg.indexOf('.')+3, '0');
    msg = msg.left(msg.indexOf('.')+3);

    here msg will contains 2 digit after decimal point.
    Last edited by rajesh; 4th October 2007 at 12:54. Reason: code modified

  3. #3
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Qt products
    Qt3 Qt4
    Platforms
    Windows
    Thanks
    7
    Thanked 25 Times in 24 Posts

    Default Re: Number formats 00.00

    if you want only 4 digit then
    QString msg = QString("%1").arg(number);
    msg = msg.leftJustified(msg.indexOf('.')+3, '0');
    msg = msg.left(msg.indexOf('.')+3);

    msg = msg.rightJustified(5,'0');
    Last edited by rajesh; 4th October 2007 at 12:53. Reason: code added

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: Number formats 00.00

    Quote Originally Posted by rajesh View Post
    QString msg = QString("%1").arg(number);
    msg = msg.leftJustified(msg.indexOf('.')+3, '0');
    msg = msg.left(msg.indexOf('.')+3);

    msg = msg.rightJustified(5,'0');
    Homework: Reduce all of this to a single line of code.

Similar Threads

  1. Line Number - QTextEdit...???
    By deepusrp in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2007, 16:34
  2. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13

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
  •  
Qt is a trademark of The Qt Company.