System.tag.write a floating number

Trying to write a floating number to a tag (value settings = memory & float).
Script works when the result is an integer, but will not work for a decimal. Just as trials, the division numerator/denominator will be varying tags when working, but the following will just move a zero in the tag.
dayPercTime = 3/22
system.tag.write("[.]..Perc_Of_Day/Perc_24hr_33", dayPercTime)

Have been unable to find anything relating to this problem or how to define i need the result as a floating number.

Hmm don't have an instance of 81 handy right now to test this but try:

dayPercTime = 3/22
system.tag.write("[.]..Perc_Of_Day/Perc_24hr_33", float(dayPercTime))

Had not tried the "float" there, had tried some other places, but still did not work.

What is the tag you are trying to write to set as?

oh sorry was in OP

That doesn't make a float in jython. That is integer division, which yields an integer. Try

dayPercTime = 3.0/22.0
2 Likes

pturmel, that worked! Now how would how would I specify a tag as a decimal(float)?

I should have written that question better:
How to make this work: the tag as the denominator is a floating value
dayPercTime = 1440.0/"[.]..Entry_Time_diff/Time_Diff_33"
system.tag.write("[.]..Perc_Of_Day/Perc_24hr_33", dayPercTime)

I have tried some variations, with no results:
dayPercTime = 1440.0/("[.]..Entry_Time_diff/Time_Diff_33")
system.tag.write("[.]..Perc_Of_Day/Perc_24hr_33", dayPercTime)

Your tag was a float. Otherwise it would have chopped off the decimals from an actual jython float.

You are dividing a float by a string. Strings containing tag paths do not magically turn into the tag value. Use some flavor of system.tag.read*().

You RULE!!!
This is what I changed the script to:
difference = system.tag.read("[.]..Entry_Time_diff/Time_Diff_33").value
dayPercTime = 1440.0/difference
system.tag.write("[.]..Perc_Of_Day/Perc_24hr_33", dayPercTime)