Results 1 to 4 of 4

Thread: round double

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2009
    Location
    Gorontalo
    Posts
    200
    Thanks
    20
    Thanked 5 Times in 5 Posts
    Qt products
    Platforms
    Unix/X11 Windows

    Question round double

    I'm looking for double round for Qt, but not lucky. qRound only round to int.

    I want round function like in postgresql

    select round(2.5275862068965517, 2); //2.53

  2. #2
    Join Date
    Aug 2009
    Posts
    52
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: round double

    Quote Originally Posted by wirasto View Post
    I'm looking for double round for Qt, but not lucky. qRound only round to int.

    I want round function like in postgresql

    select round(2.5275862068965517, 2); //2.53
    I cannot figure out what are you doing.
    But maybe what you need is a string "2.53" instead of a number 2.53 .
    If so, you can easily achieve it through QString.

  3. #3
    Join Date
    May 2009
    Location
    Gorontalo
    Posts
    200
    Thanks
    20
    Thanked 5 Times in 5 Posts
    Qt products
    Platforms
    Unix/X11 Windows

    Question Re: round double

    Fine. So how to make 2.5275862068965517 become 2.53 with QString ?

  4. #4
    Join Date
    Aug 2009
    Posts
    52
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: round double

    Quote Originally Posted by wirasto View Post
    Fine. So how to make 2.5275862068965517 become 2.53 with QString ?
    QString::number( 2.5275862068965517, 'f', 2);

    or

    QString QString::arg ( double a, int fieldWidth = 0, char format = 'g', int precision = -1, const QChar & fillChar = QLatin1Char( ' ' ) ) const

    QString & QString::sprintf ( const char * cformat, ... )

    In addition, you can also use functions in ansi C or C++ library, such as snprintf ,stringstream etc.

  5. The following user says thank you to dbzhang800 for this useful post:

    wirasto (15th December 2009)

Similar Threads

  1. Double Click Capturing
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 8th January 2011, 14:12
  2. Full Screen Double Click?
    By winston2020 in forum Qt Programming
    Replies: 4
    Last Post: 3rd June 2010, 12:37
  3. Double Clicking Pro File
    By BalaQT in forum Installation and Deployment
    Replies: 2
    Last Post: 18th November 2009, 05:23
  4. hex QByteArray to double?
    By tlt in forum Qt Programming
    Replies: 1
    Last Post: 12th July 2009, 03:33
  5. Double Buffering for plot graphs
    By Tavit in forum Qt Programming
    Replies: 0
    Last Post: 20th March 2008, 13:10

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.