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. [Solved] Truncate a “real” value in a Text field?
Forum Updated to NodeBB v4.3 + New Features

[Solved] Truncate a “real” value in a Text field?

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 2.6k 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.
  • T Offline
    T Offline
    Thanana
    wrote on 7 Oct 2011, 07:41 last edited by
    #1

    Hello there,

    I got the follow code :

    @property real compassValue : 3.1415927895412
    Text {
        text: "<b>" + compassValue + "°</b>"
    }@
    

    The fact is that I only want to display "3.14". Is there a way to troncate the value ?

    Thx for any help !

    1 Reply Last reply
    0
    • T Offline
      T Offline
      task_struct
      wrote on 7 Oct 2011, 08:01 last edited by
      #2

      QML can use JavaScript Math object. I found in Google this method:

      @
      property real compassValue : 3.1415927895412
      Text {
      text: "<b>" + Math.round(compassValue*100)/100 + "°</b>"
      }
      @

      "Source":http://www.mredkj.com/javascript/nfbasic2.html

      "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

      • Linu...
      1 Reply Last reply
      0
      • T Offline
        T Offline
        Thanana
        wrote on 7 Oct 2011, 08:07 last edited by
        #3

        very nice, thanks :)

        1 Reply Last reply
        0

        3/3

        7 Oct 2011, 08:07

        • Login

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