Results 1 to 2 of 2

Thread: values' decimal places not consistent

  1. #1
    Join Date
    Apr 2010
    Location
    Singapore
    Posts
    156
    Thanks
    47
    Qt products
    Qt4
    Platforms
    Windows

    Default values' decimal places not consistent

    Qt Code:
    1. qreal u, fYval ;
    2. fYval = 0.000;
    3. for( int i=0; i<=10; i++)
    4. {
    5. painter->drawLine(QPointF(yAxisX - 3, fYpos), QPointF(yAxisX, fYpos));
    6.  
    7. painter->drawText(QPointF(chartOuterMargin, fYpos), QString("%1").arg(fYval,0,'g',3));
    8. fYval += u;
    9. fYpos -= fStepYpos;
    10. }
    To copy to clipboard, switch view to plain text mode 

    fYval values' decimal places displayed (from code line : drawText) are inconsistent, e.g :

    fYval: 0.005
    fYval: 0.01
    fYval: 0.015
    fYval: 0.02
    fYval: 0.025
    fYval: 0.03
    fYval: 0.035
    fYval: 0.04
    fYval: 0.045
    fYval: 0.05
    fYval: 0.055

    How to make the decimal places of fYval consistent? In this case I want it to be :
    fYval: 0.005
    fYval: 0.010
    fYval: 0.015
    fYval: 0.020
    fYval: 0.025
    fYval: 0.030
    fYval: 0.035
    fYval: 0.040
    fYval: 0.045
    fYval: 0.050
    fYval: 0.055
    Last edited by babygal; 14th June 2011 at 10:40.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: values' decimal places not consistent

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

Similar Threads

  1. QPolygonF precision?! is it possible?!
    By fatecasino in forum Newbie
    Replies: 11
    Last Post: 27th January 2011, 02:36
  2. Applying a consistent background
    By KanadaKid in forum Qt Programming
    Replies: 2
    Last Post: 27th December 2009, 17:56
  3. Replies: 1
    Last Post: 15th May 2009, 07:16
  4. Replies: 2
    Last Post: 9th January 2009, 19:49
  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.