×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    272

    Question Formatting number with QString::number

    I want to display numbers without scientific notations (mantise/exponent). For this purpose I'm using this:

    Code:
    ui->lineEdit->setText(QString::number(mvTotal, 'f'));
    The problem with this is that it will set a precision of 6. If the value of mvTotal would be 1000000, it would display it 1000000.000000. Having the format 'g' instead of 'f', would display 1e+06. But what I want is that it would show it like this: 1000000. I also don't want to set a fixed precision as I want to be able to show decimal numbers too. How can I do this? Should I use something else instead of QString::number?

    Thanks

  2. #2
    Nokia Developer Champion
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Formatting number with QString::number

    Why not just explicitly specify the precision rather than taking the default value of 6?

    Or you can use sprintf() to use a C-style format string.

    Another approach is to translate the zeros to blanks, apply trimmed(), and then translate blanks back to zeros. Or just count the zeros at the end and explicitly truncate that many off. (These approaches will leave the trailing ".".)

  3. #3
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Formatting number with QString::number

    Is the question about removing trailing zeros from output produced by a following code?
    Code:
    double d = 1000000.0;
    qDebug() << QString::number(d, 'f');
    Btw, sprintf() does exactly the same with precision.

  4. #4
    Registered User
    Join Date
    Jan 2010
    Posts
    272

    Re: Formatting number with QString::number

    Quote Originally Posted by divanov View Post
    Is the question about removing trailing zeros from output produced by a following code?
    Code:
    double d = 1000000.0;
    qDebug() << QString::number(d, 'f');
    Btw, sprintf() does exactly the same with precision.
    No. I have a simple calculator where the the user enters numbers and is doesn't matter what number is entered. But I now noticed one strange thing. Those trailing zeros are not present once I compiled it to Maemo 5. However, on my Windows 7 computer they are. Quite strange...

    But since the destination platform is Maemo 5, I consider it solved.

Similar Threads

  1. Preverification failed (result=1) in build.xml
    By caradine in forum Mobile Java General
    Replies: 12
    Last Post: 2009-08-06, 07:41
  2. SIM SMS SC number - some device can not change SIM SC number
    By ashiqur in forum Symbian Signed Support, Application Packaging and Distribution and Security
    Replies: 2
    Last Post: 2009-05-18, 14:57
  3. SIM SMS SC number - E-71 can not modify SIM SC number
    By ashiqur in forum General Development Questions
    Replies: 1
    Last Post: 2009-05-14, 15:04
  4. Dialing Different number all together!!!
    By priteshgajjar in forum Symbian Networking & Messaging (Closed)
    Replies: 5
    Last Post: 2009-05-12, 06:04
  5. WML & WMLSCript problem ????
    By gemini_shooter in forum Browsing and Mark-ups
    Replies: 0
    Last Post: 2006-01-14, 06:01

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •