# System.tag.write a floating number

**URL:** <https://forum.inductiveautomation.com/t/system-tag-write-a-floating-number/69621>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [February 9, 2023, 12:45pm UTC](https://forum.inductiveautomation.com/t/system-tag-write-a-floating-number/69621 "2023-02-09T12:45:26Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ilikebeer](https://avatars.discourse-cdn.com/v4/letter/i/eb8c5e/32.png) [@ilikebeer](https://forum.inductiveautomation.com/u/ilikebeer)\
**Post date:** [February 9, 2023, 12:45pm UTC](https://forum.inductiveautomation.com/t/system-tag-write-a-floating-number/69621/1 "2023-02-09T12:45:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [February 9, 2023, 12:49pm UTC](https://forum.inductiveautomation.com/t/system-tag-write-a-floating-number/69621/2 "2023-02-09T12:49:22Z")

</div>

> [@ilikebeer](#):
>
> dayPercTime = 3/22  
> system.tag.write("[.]..Perc\_Of\_Day/Perc\_24hr\_33", dayPercTime)

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

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

```

---

<div class="post-metadata">

**Author:** ![ilikebeer](https://avatars.discourse-cdn.com/v4/letter/i/eb8c5e/32.png) [@ilikebeer](https://forum.inductiveautomation.com/u/ilikebeer)\
**Post date:** [February 9, 2023, 12:52pm UTC](https://forum.inductiveautomation.com/t/system-tag-write-a-floating-number/69621/3 "2023-02-09T12:52:11Z")

</div>

> [@ilikebeer](#):
>
> 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.

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

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [February 9, 2023, 12:53pm UTC](https://forum.inductiveautomation.com/t/system-tag-write-a-floating-number/69621/4 "2023-02-09T12:53:26Z")

</div>

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

oh sorry was in OP

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 9, 2023, 1:26pm UTC](https://forum.inductiveautomation.com/t/system-tag-write-a-floating-number/69621/5 "2023-02-09T13:26:34Z")

</div>

> [@ilikebeer](#):
>
> `dayPercTime = 3/22`

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

```auto
dayPercTime = 3.0/22.0

```

---

<div class="post-metadata">

**Author:** ![ilikebeer](https://avatars.discourse-cdn.com/v4/letter/i/eb8c5e/32.png) [@ilikebeer](https://forum.inductiveautomation.com/u/ilikebeer)\
**Post date:** [February 9, 2023, 1:36pm UTC](https://forum.inductiveautomation.com/t/system-tag-write-a-floating-number/69621/6 "2023-02-09T13:36:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ilikebeer](https://avatars.discourse-cdn.com/v4/letter/i/eb8c5e/32.png) [@ilikebeer](https://forum.inductiveautomation.com/u/ilikebeer)\
**Post date:** [February 9, 2023, 1:48pm UTC](https://forum.inductiveautomation.com/t/system-tag-write-a-floating-number/69621/7 "2023-02-09T13:48:33Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 9, 2023, 1:48pm UTC](https://forum.inductiveautomation.com/t/system-tag-write-a-floating-number/69621/8 "2023-02-09T13:48:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 9, 2023, 1:50pm UTC](https://forum.inductiveautomation.com/t/system-tag-write-a-floating-number/69621/9 "2023-02-09T13:50:08Z")

</div>

> [@ilikebeer](#):
>
> dayPercTime = 1440.0/"[.]..Entry\_Time\_diff/Time\_Diff\_33"

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*()`.

---

<div class="post-metadata">

**Author:** ![ilikebeer](https://avatars.discourse-cdn.com/v4/letter/i/eb8c5e/32.png) [@ilikebeer](https://forum.inductiveautomation.com/u/ilikebeer)\
**Post date:** [February 9, 2023, 2:33pm UTC](https://forum.inductiveautomation.com/t/system-tag-write-a-floating-number/69621/10 "2023-02-09T14:33:35Z")

</div>

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)
