Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Text component. double variable as source. Number of digits after comma.
Forum Updated to NodeBB v4.3 + New Features

Text component. double variable as source. Number of digits after comma.

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 552 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.
  • K Offline
    K Offline
    Kuzma30
    wrote on last edited by
    #1

    I have example Text. It show 11.111111. How to specify how many digits it must show after comma? I want 2 digits. Like 11.11.

    Text {
                   anchors.fill: parent
                   verticalAlignment: Text.AlignVCenter
                   horizontalAlignment: Text.AlignHCenter
                   font.pointSize: 0.6*parent.height
                   text: 11.111111
               }
    
    1 Reply Last reply
    0
    • mzimmersM Offline
      mzimmersM Offline
      mzimmers
      wrote on last edited by mzimmers
      #2
      text: Number(11.111111).toFixed(2)
      

      I thought this would work, too, but it doesn't:

      text: Number(11.111111).toLocaleString("de_DE", 'f', 2)
      

      Perhaps someone else can shed some light on this.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Kuzma30
        wrote on last edited by
        #3

        @mzimmers said in Text component. double variable as source. Number of digits after comma.:

        text: Number(11.111111).toFixed(2)

        This works fine

        text: qsTr("%1 km/h").arg(Number(rate.speed).toFixed(2))
        
        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