Results 1 to 5 of 5

Thread: how to set double precision

  1. #1
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: how to set double precision

    My double is 00.0 format. when I set it to QLCDNumber .display(double)
    it automatically removes the precisions and displays 0

    02.0 -> as 2.0
    0.0 -> 0
    20.0 -> 20
    and so on. How can I force it keep it's format?


    Added after 9 minutes:


    Quote Originally Posted by saman_artorious View Post
    My double is 00.0 format. when I set it to QLCDNumber .display(double)
    it automatically removes the precisions and displays 0

    02.0 -> as 2.0
    0.0 -> 0
    20.0 -> 20
    and so on. How can I force it keep it's format?
    I did this:
    QString str = QString::number(f, 'f', 1);

    now, how can I padleft the float? so that when I enter 02.0 it shows it and not 2.0? does qt support it?
    Last edited by saman_artorious; 27th February 2013 at 10:27.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to set double precision

    Read about QString::rightJustified. And for the future: read the documentation, it does not hurt.

  3. #3
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: how to set double precision

    Quote Originally Posted by Lesiok View Post
    Read about QString::rightJustified. And for the future: read the documentation, it does not hurt.
    result is not as expected. had to do this to get the expected result:
    Qt Code:
    1. QString str = QString::number(f, 'f', 1);
    2. if(str.length() == 3)
    3. str.insert(0, '0');
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to set double precision

    Qt Code:
    1. QString(%1).arg(f, 5, 'f', 1, '0');
    To copy to clipboard, switch view to plain text mode 

    or similar. RightJustified() would also work.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    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: how to set double precision

    it automatically removes the precisions and displays 0
    02.0 -> as 2.0
    A leading zero has nothing to do with precision.

Similar Threads

  1. Replies: 16
    Last Post: 21st May 2011, 13:22
  2. Print floating and double precision number
    By marc2050 in forum Newbie
    Replies: 2
    Last Post: 17th May 2011, 09:15
  3. Replies: 7
    Last Post: 28th December 2010, 21:27
  4. The precision range of double
    By nikhilqt in forum Qt Programming
    Replies: 14
    Last Post: 8th July 2009, 16:08
  5. double precision or what?
    By mickey in forum General Programming
    Replies: 7
    Last Post: 20th February 2007, 21: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.