Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QString::number() with a strange problem
Forum Updated to NodeBB v4.3 + New Features

QString::number() with a strange problem

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 315 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • MihanM Offline
    MihanM Offline
    Mihan
    wrote on last edited by
    #1

    Hi all

    I found a little problem on [static]QString QString::number(double n, char format = 'g', int precision = 6)
    e.g.

    QString::number(22.50, "f", 0);   //it could not be "23";
    QString::number(23.50, "f", 0);   //it could be "24";
    QString::number(22.53, "f", 0);   //it could be "23";
    

    Is that right, or could you please tell me how to round the number in this code?

    Best regards
    Mihan

    jsulmJ 1 Reply Last reply
    0
    • MihanM Mihan

      Hi all

      I found a little problem on [static]QString QString::number(double n, char format = 'g', int precision = 6)
      e.g.

      QString::number(22.50, "f", 0);   //it could not be "23";
      QString::number(23.50, "f", 0);   //it could be "24";
      QString::number(22.53, "f", 0);   //it could be "23";
      

      Is that right, or could you please tell me how to round the number in this code?

      Best regards
      Mihan

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Mihan said in QString::number() with a strange problem:

      number

      If you want to round numbers properly you should use https://doc.qt.io/archives/qt-4.8/qtglobal.html#qRound instead of QString.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved