Simple Rounding Question

Posted on
Mon Jun 10, 2019 8:27 pm
jltnol offline
Posts: 989
Joined: Oct 15, 2013

Simple Rounding Question

I'm keeping tabs on something that outputs in seconds... but there are thousands of them, so the number is meaningless. I'm trying to get the seconds converted to hours, which I've been able to do, but would like to keep the answer to 2 decimal places.

Here is my original code:
Code: Select all
theDifa =str(float(theVar1.value) /3600) #seconds into hours
indigo.variable.updateValue(1924530586, ((theDifa)))

and this is what I get:
7.53694444444

and here's ONE of the things I've tried, but of course, it doesn't work:
Code: Select all
theDifa =str(float(theVar1.value) /3600)   #seconds into hours
answer = str(round(theDifa, 2))
indigo.variable.updateValue(1924530586, ((theDifaR1)))


So basically, I'm taking the value of theVar1, divide by 3600 (seconds in an hour), then truncate the answer to 2 decimal places, and then put it back into a Indigo Variable. Do I need to create a new variable to be the x,2 number, and then put that back into the Indigo Variable ?

Posted on
Mon Jun 10, 2019 8:37 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Simple Rounding Question

Code: Select all
theDifa = "{:.2f}".format(theVar1.value /3600.0)
indigo.variable.updateValue(1924530586, theDifa)
 

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon Jun 10, 2019 8:51 pm
jltnol offline
Posts: 989
Joined: Oct 15, 2013

Re: Simple Rounding Question

Hey Joe

Thanks for your help, the code passes the compiler, but I'm getting an error message:

Code: Select all
Script Error                    embedded script: unsupported operand type(s) for /: 'unicode' and 'float'
   Script Error                    Exception Traceback (most recent call shown last):

     embedded script, line 14, at top level
TypeError: unsupported operand type(s) for /: 'unicode' and 'float'


I'm totally in the dark here as to what the error means, much less how to fix it.

Thanks

Posted on
Mon Jun 10, 2019 8:53 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Simple Rounding Question

I think this works:

Code: Select all
theDifa = "{:.2f}".format(theVar1.floatValue /3600.0)
indigo.variable.updateValue(1924530586, theDifa)


If not, this will:

Code: Select all
theDifa = "{:.2f}".format(float(theVar1.value) /3600.0)
indigo.variable.updateValue(1924530586, theDifa)

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon Jun 10, 2019 8:54 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Simple Rounding Question

jltnol wrote:
I'm totally in the dark here as to what the error means, much less how to fix it.


Means that theVar1.value was returning a unicode string, not a float. My bad.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon Jun 10, 2019 9:05 pm
jltnol offline
Posts: 989
Joined: Oct 15, 2013

Re: Simple Rounding Question

The 2nd one works perfectly

Thanks again for your help. :D

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests