• Recent
    • Tags
    • Popular
    • Register
    • Login

    Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    ma-point-value: number formatting

    How-To
    5
    10
    3.1k
    Loading More Posts
    • 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.
    • M
      mrlucretius
      last edited by

      I have an ma-point-value like so. By default it prints out 2 decimal places.

      How can I change the format to zero digits after decimal, or other formats?

                  <ma-point-value id="dp-m1-houses" style="width: 40%; height: 25px; text-align: left; margin-left: 20px;" point-xid="DP_4d6ba9d6-116a-4922-9841-515a22710174" enable-popup="hide"></ma-point-value>
      

      Default format:

      0_1536610527408_2ef7b56b-db4b-45d2-af08-ccbd4d739cc4-image.png

      Thanks,
      Alex

      1 Reply Last reply Reply Quote 0
      • MattFoxM
        MattFox
        last edited by MattFox

        You can use in the text format settings for the respective points on the data sources page /data_sources.shtm (this applies to the rendered value only)
        0_1536611143189_2e34dbd7-bfcf-42e4-8481-71bf96c8bcc3-image.png
        Alternatively:
        Use
        <ma-get-point-value point-xid="DP_4d6ba9d6-116a-4922-9841-515a22710174" point="point"></ma-get-point-value>
        instead and with the point attribute use: {{parseInt(point.value)}} for only one decimal place use {{ point.value.toFixed(1)}}

        Plenty of resources are available in the vanilla javascript Math class:
        https://devdocs.io/javascript-math/

        Hope that helps

        Fox

        Do not follow where the path may lead; go instead where there is no path.
        And leave a trail - Muriel Strode

        ThomasEinastoT 1 Reply Last reply Reply Quote 1
        • ThomasEinastoT
          ThomasEinasto @MattFox
          last edited by

          @mattfox said

          instead and with the point attribute use: {{parseInt(point.value)}} for only one decimal place use {{ point.value.toFixed(1)}}

          Oh, you can use javascript functions inside the brackets of html ? I thought that you can only do basic math functions inside the brackets.

          Good to know @MattFox :)

          1 Reply Last reply Reply Quote 0
          • MattFoxM
            MattFox
            last edited by

            You can albeit only the basic ones. As you will have discovered, anything requiring more than simple logic will need a component or a controller to manipulate data.

            Do not follow where the path may lead; go instead where there is no path.
            And leave a trail - Muriel Strode

            1 Reply Last reply Reply Quote 0
            • B
              BobDay
              last edited by Jared Wiltshire

              @mattfox said in ma-point-value: number formatting:

              point.value.toFixed(1)

              you can also use a built-in Angular filter -
              {{point.value | number(decimal places)}}

              ...even when doing things you can't do more than basics - like
              {{point.value*256 | number(1)}}

              edit. Jared Wiltshire - examples given here are incorrect, see post by @Puckfist below.

              1 Reply Last reply Reply Quote 1
              • MattFoxM
                MattFox
                last edited by

                Also true, but not everyone on this forum likes to play with JavaScript and are quite content with using what is available without making things too difficult for themselves.

                Do not follow where the path may lead; go instead where there is no path.
                And leave a trail - Muriel Strode

                1 Reply Last reply Reply Quote 0
                • B
                  BobDay
                  last edited by BobDay

                  Excuse me @MattFox - I thought you were discussing a javascript method solution in your answer. And, to your point, quite often what is "available" in the wonderful collection of Mango is not entirely obvious without a lot of time searching in multiple places - so some of us need to be content to use what we know. I'll try to refrain from suggesting javascript (actually angular components) in the future.

                  1 Reply Last reply Reply Quote 0
                  • MattFoxM
                    MattFox
                    last edited by

                    Far from it, if you have a solution that can benefit someone, show it and give examples. That's what this forum is for. All I am saying is that not everyone is comfortable as soon as you start mentioning filters or components etc.
                    Yes what you have done works but sometimes simplicity is key.

                    Do not follow where the path may lead; go instead where there is no path.
                    And leave a trail - Muriel Strode

                    1 Reply Last reply Reply Quote 1
                    • phildunlapP
                      phildunlap
                      last edited by

                      It's definitely good to contribute methods of doing stuff, but it's best if those methods work (insert links to the many times I've said "untested" next to code snippets here...)

                      I think your parameters to the angular filter have a syntax error, they should be colon delimited, as,

                      {{point.value | number:N}}
                      

                      where N is the number of decimal places, like,

                      {{point.value*256 | number:1}}
                      
                      1 Reply Last reply Reply Quote 2
                      • B
                        BobDay
                        last edited by

                        Correct! and point well taken - absolutely dumb mistake.

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post