# toInt, toLong Inconsistent Results

**URL:** <https://forum.inductiveautomation.com/t/toint-tolong-inconsistent-results/15504>\
**Category:** Ignition\
**Created:** [September 28, 2017, 9:20pm UTC](https://forum.inductiveautomation.com/t/toint-tolong-inconsistent-results/15504 "2017-09-28T21:20:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mcgheeiv](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@mcgheeiv](https://forum.inductiveautomation.com/u/mcgheeiv)\
**Post date:** [September 28, 2017, 9:20pm UTC](https://forum.inductiveautomation.com/t/toint-tolong-inconsistent-results/15504/1 "2017-09-28T21:20:45Z")

</div>

Ignition 7.9.4

Attempting to use toInt to enable a button when an integer has been typed into a text box. If the user types 1234-a, this function returns 1234, not the fallback value.

Thanks!

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [September 28, 2017, 11:43pm UTC](https://forum.inductiveautomation.com/t/toint-tolong-inconsistent-results/15504/2 "2017-09-28T23:43:52Z")

</div>

Looks like our type-casting just strips alpha characters when attempting the conversion. I’ll let a dev answer whether that’s expected behavior or not - but in the meantime, you could use a [Formatted Text Field](https://docs.inductiveautomation.com/display/DOC79/Formatted+Text+Field) to restrict which input characters are allowed.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [September 29, 2017, 5:15pm UTC](https://forum.inductiveautomation.com/t/toint-tolong-inconsistent-results/15504/3 "2017-09-29T17:15:03Z")

</div>

Option 2: add a custom property (something like isInt, or whatever makes sense for you) to check if it really is an integer:

```auto
{Root Container.Text Field.text} = toStr(toInt({Root Container.Text Field.text}))

```

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [September 29, 2017, 6:54pm UTC](https://forum.inductiveautomation.com/t/toint-tolong-inconsistent-results/15504/4 "2017-09-29T18:54:12Z")

</div>

We’re using Java’s NumberFormat to do the parsing, and it strips out anything that doesn’t look like a number. So yeah, intended behavior.
