Results 1 to 3 of 3

Thread: Print floating and double precision number

  1. #1
    Join Date
    Apr 2011
    Posts
    58
    Thanks
    1

    Default Print floating and double precision number

    Hi.

    I've a number y = 0.62354642

    When I try
    QString("%1").arg(y)

    It does not show on my screen the full 0.62354642.
    Rather is shows the value of '1'.
    My variables are declared as float. And I've been able to output variables values on my screen. But it is the first time I'm trying to see the values in float precision.
    How do I see the results up to the exact decimal places?

    Thanks.

  2. #2
    Join Date
    Feb 2011
    Location
    Romania
    Posts
    53
    Thanks
    1
    Thanked 11 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Print floating and double precision number

    You can simply use setNum

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

    Default Re: Print floating and double precision number

    Quote Originally Posted by marc2050 View Post
    I've a number y = 0.62354642

    When I try
    QString("%1").arg(y)

    It does not show on my screen the full 0.62354642.
    Rather is shows the value of '1'.
    Then the value y is 1 (or within a small margin of it) not 0.62354642. Have you done an integer operation/assignment somewhere? Or have just left out the percent sign in the QString template?

    Qt Code:
    1. double y1 = 0.62354642;
    2. float y2 = 0.62354642;
    3. qDebug() << QString("%1").arg(y1) << QString::number(y1, 'g', 8) ;
    4. qDebug() << QString("%1").arg(y2) << QString::number(y2, 'g', 8) ;
    To copy to clipboard, switch view to plain text mode 
    outputs:
    Qt Code:
    1. "0.623546" "0.62354642"
    2. "0.623546" "0.62354642"
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 7
    Last Post: 28th December 2010, 20:27
  2. The precision range of double
    By nikhilqt in forum Qt Programming
    Replies: 14
    Last Post: 8th July 2009, 15:08
  3. Replies: 1
    Last Post: 24th July 2008, 18:20
  4. how can a pixel be a floating point number
    By babu198649 in forum General Programming
    Replies: 1
    Last Post: 2nd June 2008, 18:05
  5. double precision or what?
    By mickey in forum General Programming
    Replies: 7
    Last Post: 20th February 2007, 20:01

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.