Results 1 to 2 of 2

Thread: Remove traling zeros from QString scientific notation num value

  1. #1
    Join Date
    Apr 2020
    Posts
    1

    Default Remove traling zeros from QString scientific notation num value

    I have the next code, this code print a value in scientific notation, but i want to remove the trailing zeros

    valor = 541; QString cStyleResult = QString::number(valor.toDouble(), 'e');

    qDebug() << cStyleResult ;

    //////////////////////////////////////////////
    output: 5.410000e2

    I want to remove the trailing zeros(right decimal zeros), example I want to save only the value of 5.41

    some ideas????

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    512
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Remove traling zeros from QString scientific notation num value

    Hi, you could
    - specifiy a precision as the third parameter for QString::number
    - you could use QString::arg() and play with fieldwidth and precision
    - you could take your string, find the e or E of the scientific notation, and remove all zeroes in front of it (probably the ugliest method...)
    - probably many more...

    Ginsengelf

Similar Threads

  1. Replies: 1
    Last Post: 9th March 2019, 09:15
  2. Remove \n from QString
    By arturs in forum Newbie
    Replies: 4
    Last Post: 20th April 2015, 08:41
  3. Replies: 3
    Last Post: 17th April 2010, 21:35
  4. qdoublespinbox with scientific notation
    By pospiech in forum Qt Programming
    Replies: 13
    Last Post: 3rd January 2009, 14:50
  5. QString:: Padding Zeros?
    By Harvey West in forum Qt Programming
    Replies: 2
    Last Post: 27th February 2007, 18:25

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.