Announcement

Collapse
No announcement yet.

is there a way to round a number

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    is there a way to round a number

    I'm storing a value in a HS device in seconds that I want to display in minutes. I'm already using the round function in HSTouch to divide it by 60. Is there a way to round a number that comes from a device value in HS in a HSTouch screen? Right now I'm getting 7.5833333333 which is kind of annoying to look at.

    Jabran

    #2
    If you are you using the Round function then it has a optional parameter to specify the number of decimal places. Like this;

    [$SCRIPT=&Round(Rnd(),2)] - which would round a random number to two DP.

    I'm not sure what command you are using as to whether it would work, the other option is to read x number of digits using the 'Left(String, 2)' or similar...

    Comment


      #3
      hmmm, I'm not using a script. I've just got a HS device that has a number in it which is 455. I want to display it in HSTouch divided by 60 since 455 is in seconds. So 455 / 60 = 7.5833333333. So HSTouch is displaying 7.5833333333. I'd like it to display in HSTouch as 7.6.

      Comment


        #4
        x=int(x*10)/10 will get you 1 decimal place
        x=int(X*100)/100 will get you 1 decimal places

        And so on


        ~Bill

        Comment


          #5
          Originally posted by jabrans View Post
          hmmm, I'm not using a script. I've just got a HS device that has a number in it which is 455. I want to display it in HSTouch divided by 60 since 455 is in seconds. So 455 / 60 = 7.5833333333. So HSTouch is displaying 7.5833333333. I'd like it to display in HSTouch as 7.6.
          There's no way I know of to format numbers in HSTouch, which is a shame. I would like to do the same thing. If you know the mantissa is going to be a ingle digit, only thing I could suggest it put in test box and align LEFT and make the box only big enough for 3 chars plus decimal point (or cover right hand side of box)

          Only other solution is to have script that trigger on a value change and have that do the rounding and update a variable/virtual device, which you would use to display. Would only do that if value changed infrequently though. Other option (if the screen you're loading is loaded on a button click is to update a variable/virtual device when the screen loads and then display that on the new screen).
          ________________________

          Dell Zino HD - HSPRo 2.x
          HSTouch - iPhone 3GS, 4S, iPad2 and iPad 3, 3xKindle Fire (Wall mounted)
          2 x Brultech ECM1240 with UltraECM
          USB UIRT
          Cooper Aspire Z-Wave Switches
          WGL800 w ACRF2 and 3xDS10a (Sump Level/Activity sensing)
          HM ST812-2 Flood Sensor
          HSM100 - Motion Detector with Light and Temperature
          2GIG Thermostat
          BLDSC - Alarm Plug-in
          BLUPS
          UltraLog (SQL2008)
          Jon00 Plugins
          Host XR3 BT and Jon00 BT Proximity
          Global Cache IP2IR
          Foscam FI8918W

          Comment


            #6
            Originally posted by jabrans View Post
            hmmm, I'm not using a script. I've just got a HS device that has a number in it which is 455. I want to display it in HSTouch divided by 60 since 455 is in seconds. So 455 / 60 = 7.5833333333. So HSTouch is displaying 7.5833333333. I'd like it to display in HSTouch as 7.6.
            Did you try mrhappys code round code he posted?
            💁‍♂️ Support & Customer Service 🙋‍♂️ Sales Questions 🛒 Shop HomeSeer Products

            Comment


              #7
              Originally posted by Rupp View Post
              Did you try mrhappys code round code he posted?
              If you're trying to do status tracking, then no, there's nothing to do what you want without creating a phantom/virtual device which contains the rounded value.


              If on the other hand, it's just a raw text box type of thing, in the text field, put this

              {Assume your device code is A1...}

              [$SCRIPT=&Round($$DV:A1,2)]

              Works like a champ and it's built in as an option... only wish the $SCRIPT command had an update rate value to choose update frequency (1s, 1m, etc.) to reduce traffic especially if the value only changes hourly.
              huggy_d1

              Automating made easy

              Comment


                #8
                So I decided to go the route of another device to hold the value in minutes rounded to two decimal places. The main variable only changes once a month and I'm already running a script to change it so it is easy enough to add a few lines. So I've got the "minute" device value in HS as 7.58 and when I display it in HSTouch I get "8"!

                Script:
                newValueMin = round((455/60),2)
                hs.SetDeviceValue "T81",newValueMin
                hs.writelog "Debug", "Custom Value 1 minute is: " & newValueMin

                Log:
                8/11/2011 10:40:04 PM Debug Custom Value 1 minute is: 7.58

                HSTouch:
                using Status/Device - StatusTrackingNormal

                attached screen snips showing HSTouch config and display
                Attached Files

                Comment


                  #9
                  Set the device string, and display the device string. Device values are integer values, so when you assigned it to the device value, it rounded to 8 for you.
                  huggy_d1

                  Automating made easy

                  Comment


                    #10
                    Thanks, the string is what I wanted.

                    Jabran

                    Comment


                      #11
                      Is there any way to format a number? That is, if the value of a device is, for example, 12345.678, I can use Round() to round or Int() to get it to an integer, but what about comma placeholders, i.e. 12,345? The Format() function does not work in HST, though it works in scripts.

                      -BD

                      Comment

                      Working...
                      X