Results 1 to 8 of 8

Thread: Conversion from string to double and precision

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Conversion from string to double and precision

    Your qDebug() line is converting a double to a string in a default format (See the double version of QLocale::toString() and the source to the QDebug << operator):
    Qt Code:
    1. double d = c.toDouble("44.48666300");
    2. qDebug() << d;
    3. qDebug() << QString::number(d);
    4. qDebug() << c.toString(d, 'f', 10);
    To copy to clipboard, switch view to plain text mode 
    outputs:
    Qt Code:
    1. 44.4867
    2. "44.4867"
    3. "44.4866630000"
    To copy to clipboard, switch view to plain text mode 
    All the possible bits of the floating point representation of your original string are in the double. Note that this may still be an approximation due to the nature of floats.
    Last edited by ChrisW67; 25th March 2010 at 23:40. Reason: Add where to find the defaults

  2. The following user says thank you to ChrisW67 for this useful post:

    Klenje (26th March 2010)

Similar Threads

  1. int to String Conversion
    By aj2903 in forum Qt Programming
    Replies: 4
    Last Post: 4th December 2009, 23:43
  2. The precision range of double
    By nikhilqt in forum Qt Programming
    Replies: 14
    Last Post: 8th July 2009, 16:08
  3. Replies: 1
    Last Post: 24th July 2008, 19:20
  4. Conversion Char Array to string
    By anafor2004 in forum Newbie
    Replies: 6
    Last Post: 6th May 2008, 15:35
  5. double precision or what?
    By mickey in forum General Programming
    Replies: 7
    Last Post: 20th February 2007, 21:01

Tags for this Thread

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.