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. Preventing QLocale::toString(double) from displaying number in scientific notation?

Preventing QLocale::toString(double) from displaying number in scientific notation?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.0k Views
  • 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.
  • Q Offline
    Q Offline
    Qt_User72653
    wrote on last edited by
    #1

    I'm using QLocale::toString(double) to display numbers with commas (e.g., display 1000000 as 1,000,000). The issue I'm having is that if the number would overflow the widget it's displayed in it's displayed using scientific notation.

    Is there a way to prevent this?

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      Yes it's in the docs: http://doc.qt.io/qt-5/qlocale.html#toString-6

      QLocale::toString(double,'f')

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      2
      • Q Offline
        Q Offline
        Qt_User72653
        wrote on last edited by
        #3

        I previously tried the 'f' flag but if I enter 1000000 I wind up with 102.

        I think it might be easier to just use toCurrencyString() and strip the leading '$'.

        VRoninV 1 Reply Last reply
        0
        • Q Qt_User72653

          I previously tried the 'f' flag but if I enter 1000000 I wind up with 102.

          I think it might be easier to just use toCurrencyString() and strip the leading '$'.

          VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          @Qt_User72653 said in Preventing QLocale::toString(double) from displaying number in scientific notation?:

          but if I enter 1000000

          1000000 is an integer literal in C++ QLocale::toString(1000000.0,'f') should work

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          4

          • Login

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