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. How to set the Precision for the Decimal Values?
Qt 6.11 is out! See what's new in the release blog

How to set the Precision for the Decimal Values?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 7.1k 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.
  • J Offline
    J Offline
    JoyRider
    wrote on last edited by
    #1

    Can anyone please help me how to set the precision for the Decimal Values. In my Line Edit i can enter any number of integer values & i want to set the precision for the decimal values. When i am entering a value in Line Edit the decimal values should not exceed more than 3 decimals. How can i set the precision for this decimals values?

    Example:
    123.456
    23456.057
    1.593.

    Note: i have to set the Precision only for the Decimal Values.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Macro
      wrote on last edited by
      #2

      Try this way...

      @QString::number( double n, char format = 'g', int precision = 3)@

      1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Or, if you care about other nations, you can use this:
        @
        QLocale().toString( n, 'g', 3 )
        @

        1 Reply Last reply
        0

        • Login

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