# Unable to get toInt to work

**URL:** <https://forum.inductiveautomation.com/t/unable-to-get-toint-to-work/101244>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [January 22, 2025, 6:14pm UTC](https://forum.inductiveautomation.com/t/unable-to-get-toint-to-work/101244 "2025-01-22T18:14:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![AHigginbotham](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@AHigginbotham](https://forum.inductiveautomation.com/u/AHigginbotham)\
**Post date:** [January 22, 2025, 6:14pm UTC](https://forum.inductiveautomation.com/t/unable-to-get-toint-to-work/101244/1 "2025-01-22T18:14:42Z")

</div>

Unable to get toInt to work. I have a OPC tag that is a String and I want to convert it to an INT. I have created an expression tag with toint ({[.]Alarm Code.value},-1). Most of the time it reports back -1 but every once in a while it shows the correct value of the other tag then goes back to -1 even thought the string value is 31.

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [January 22, 2025, 6:33pm UTC](https://forum.inductiveautomation.com/t/unable-to-get-toint-to-work/101244/2 "2025-01-22T18:33:54Z")

</div>

While I don't think it should matter, try making it just `toInt({[.]Alarm Code}, -1)` to remove the `.value` as it's the default anyway, but not sure if it could cause any issues with what you're seeing. Also, I'm assuming this is inside a UDT since you're using `[.]`. Are there any spaces or other "hidden" characters part of the string that could be causing an error when it reads -1?

---

<div class="post-metadata">

**Author:** ![AHigginbotham](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@AHigginbotham](https://forum.inductiveautomation.com/u/AHigginbotham)\
**Post date:** [January 22, 2025, 6:53pm UTC](https://forum.inductiveautomation.com/t/unable-to-get-toint-to-work/101244/3 "2025-01-22T18:53:02Z")

</div>

That was the way I had it originally and I did just try again to no aval. I did just try renaming the original tag taking out the space and im still having the same issue.

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [January 22, 2025, 6:57pm UTC](https://forum.inductiveautomation.com/t/unable-to-get-toint-to-work/101244/4 "2025-01-22T18:57:28Z")

</div>

What about wrapping the tag in a `trim()` function as well as a precaution?

```python
toInt(trim({[.]Alarm Code}), -1)

```

---

<div class="post-metadata">

**Author:** ![AHigginbotham](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@AHigginbotham](https://forum.inductiveautomation.com/u/AHigginbotham)\
**Post date:** [January 22, 2025, 7:01pm UTC](https://forum.inductiveautomation.com/t/unable-to-get-toint-to-work/101244/5 "2025-01-22T19:01:00Z")

</div>

That worked, Question why did that work?

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [January 22, 2025, 7:01pm UTC](https://forum.inductiveautomation.com/t/unable-to-get-toint-to-work/101244/6 "2025-01-22T19:01:50Z")

</div>

Most likely some extra whitespace or characters you possibly weren't seeing that it stripped off before trying to convert to an integer.

---

<div class="post-metadata">

**Author:** ![AHigginbotham](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@AHigginbotham](https://forum.inductiveautomation.com/u/AHigginbotham)\
**Post date:** [January 22, 2025, 7:03pm UTC](https://forum.inductiveautomation.com/t/unable-to-get-toint-to-work/101244/7 "2025-01-22T19:03:31Z")

</div>

Perfect, Thank you for your help. Was really banging my head on this simple one.
