# Trying to scale an OPC integer down to a float

**URL:** <https://forum.inductiveautomation.com/t/trying-to-scale-an-opc-integer-down-to-a-float/71778>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [March 29, 2023, 3:32pm UTC](https://forum.inductiveautomation.com/t/trying-to-scale-an-opc-integer-down-to-a-float/71778 "2023-03-29T15:32:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cole\_Townsend](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cole_townsend/32/53149_2.png) [@Cole\_Townsend](https://forum.inductiveautomation.com/u/Cole_Townsend)\
**Post date:** [March 29, 2023, 3:32pm UTC](https://forum.inductiveautomation.com/t/trying-to-scale-an-opc-integer-down-to-a-float/71778/1 "2023-03-29T15:32:26Z")

</div>

So I am trying to scale an integer that is coming from an OPC source down to a float. For example, if the source gives me 578, I want the tag to have the value 5.78.

The issue I am running into here is that if I pull the integer from the OPC source as an integer, it will round the scaled-down value to the nearest integer value. Because of this, the tag scaling will return 6.0 instead of 5.78. If I change the tag type to a float, it will not properly poll the Modbus address.

Is there any workaround to this issue? Another stipulation that makes this a little more difficult is that I want to read and write to this value as well.

Thanks for any help you guys can give.

---

<div class="post-metadata">

**Author:** ![mmunin](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@mmunin](https://forum.inductiveautomation.com/u/mmunin)\
**Post date:** [March 29, 2023, 3:41pm UTC](https://forum.inductiveautomation.com/t/trying-to-scale-an-opc-integer-down-to-a-float/71778/2 "2023-03-29T15:41:07Z")

</div>

Hmm i'm not sure if there's going to be a way of doing this that's as elegant as you might hope. For a "read only" context you can just create an expression tag that's of datatype float, and is equal to your integer opc tag / 100.0

To be able to write a value of 5.78 to that tag and then have it push 578 to the OPC tag is more complicated. If it were me I would keep the tag as the integer OPC and have whatever graphics in your perspective/vision app handle the conversion.

So you might have a label's text binding be to your tag, with a transform that divides by 100.0. And a numeric entry field with a property change script that writes "toInt(value\* 100)" to the target tag.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 29, 2023, 3:41pm UTC](https://forum.inductiveautomation.com/t/trying-to-scale-an-opc-integer-down-to-a-float/71778/3 "2023-03-29T15:41:21Z")

</div>

You need to change the Ignition tag datatype to float while leaving the underlying Modbus address as an integer type, then set up tag scaling.

---

<div class="post-metadata">

**Author:** ![Cole\_Townsend](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cole_townsend/32/53149_2.png) [@Cole\_Townsend](https://forum.inductiveautomation.com/u/Cole_Townsend)\
**Post date:** [March 29, 2023, 4:30pm UTC](https://forum.inductiveautomation.com/t/trying-to-scale-an-opc-integer-down-to-a-float/71778/4 "2023-03-29T16:30:52Z")

</div>

I had assumed that I would have had to change the modbus command from HRI to HRF if the tag type was changed, but I guess ignition is pretty flexible and type casts to whatever the tag type is.

Thanks
