Results 1 to 2 of 2

Thread: Strange QString::number behaviour

  1. #1
    Join Date
    Sep 2011
    Posts
    2
    Thanks
    1

    Default Strange QString::number behaviour

    Hello

    I am facing a strange behaviour of QString::number that I can not explain even after reading the documentation over and over again.

    Qt Code:
    1. qDebug() << QString::number( 62.5, 'g' );
    2. qDebug() << QString::number( 62.5, 'g', 1 );
    3. qDebug() << QString::number( 62.5, 'g', 2 );
    4. qDebug() << QString::number( 62.5, 'g', 4 );
    5. qDebug() << QString::number( 62.5, 'g', 5 );
    6. qDebug() << QString::number( 62.5, 'g', 6 );
    To copy to clipboard, switch view to plain text mode 

    Produces this output:

    Qt Code:
    1. "62.5"
    2. "6e+01"
    3. "62"
    4. "62.5"
    5. "62.5"
    6. "62.5"
    To copy to clipboard, switch view to plain text mode 

    Now I dont understand why the "62" without the .5 result of the result line from "qDebug() << QString::number( 62.5, 'g', 2 ); "


    Any explaination on what I am doing wrong? The format options 'e' and 'f' are not interessting for me right now.

    Greetings
    sas

  2. #2
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Strange QString::number behaviour

    g/ G return whichever among e/E or F is more concise.
    with 2 precision, f gives 62.5, e gives 62, with trailing zeroes being omitted. Which is more concise?
    Both g and G never made sense to use. use f or e to be sure.

  3. The following user says thank you to pkj for this useful post:

    sastrian (7th September 2012)

Similar Threads

  1. QString operator+= strange behaviour
    By babu198649 in forum Newbie
    Replies: 13
    Last Post: 17th January 2010, 05:54
  2. QMainWindow - strange behaviour
    By franco.amato in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2009, 23:44
  3. Need help: Strange behaviour
    By navi1084 in forum Qt Programming
    Replies: 3
    Last Post: 14th November 2008, 04:03
  4. strange problem about QString::number(double)
    By yuzr in forum Qt for Embedded and Mobile
    Replies: 4
    Last Post: 24th December 2007, 13:05
  5. very strange behaviour
    By regix in forum Qt Programming
    Replies: 23
    Last Post: 20th July 2006, 17:38

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.