# \[Bug\] Typecasting doesn't work when trying to add

**URL:** <https://community.thunkable.com/t/bug-typecasting-doesnt-work-when-trying-to-add/10043>\
**Category:** Questions about Thunkable X\
**Tags:** beginner\
**Created:** [November 2, 2017, 6:57pm UTC](https://community.thunkable.com/t/bug-typecasting-doesnt-work-when-trying-to-add/10043 "2017-11-02T18:57:16Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Teacher\_Mah](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Teacher\_Mah](https://community.thunkable.com/u/Teacher_Mah)\
**Post date:** [November 2, 2017, 6:57pm UTC](https://community.thunkable.com/t/bug-typecasting-doesnt-work-when-trying-to-add/10043/1 "2017-11-02T18:57:16Z")

</div>

My goal is to create a simple calculator by setting two user input boxes into variables, and using those variables to add/subtract/multiply/divide each other, saving it in a final result variable.

Thunkable iOS correctly calculates two values when it is subtracted, multiplied, or divided. However the addition function believes the variables are a String instead of an Int.

I tested the same function with numerical values and it calculates properly. I am not sure if the bug is with the typecasting or addition.

 ![](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/2X/e/e6bf315f7ceed688be34231639104600dd5b657d.png)

 ![](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/2X/7/71359c7f3c42a085c82503a3bda2d355eb064c90.png)

Any help would be appreciated.

Thanks!

---

<div class="post-metadata">

**Author:** ![domhnallohanlon](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/domhnallohanlon/32/29554_2.png) [@domhnallohanlon](https://community.thunkable.com/u/domhnallohanlon)\
**Post date:** [November 2, 2017, 7:06pm UTC](https://community.thunkable.com/t/bug-typecasting-doesnt-work-when-trying-to-add/10043/2 "2017-11-02T19:06:35Z")

</div>

So what’s happening? Does it concatenate the strings? i.e if your try 1+ 2 do you get “12” instead of 3?

---

<div class="post-metadata">

**Author:** ![Teacher\_Mah](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Teacher\_Mah](https://community.thunkable.com/u/Teacher_Mah)\
**Post date:** [November 2, 2017, 7:08pm UTC](https://community.thunkable.com/t/bug-typecasting-doesnt-work-when-trying-to-add/10043/3 "2017-11-02T19:08:22Z")

</div>

Yes exactly, but 1-2, 1\*2, and 1/2 are all working correctly.

---

<div class="post-metadata">

**Author:** ![domhnallohanlon](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/domhnallohanlon/32/29554_2.png) [@domhnallohanlon](https://community.thunkable.com/u/domhnallohanlon)\
**Post date:** [November 4, 2017, 10:25pm UTC](https://community.thunkable.com/t/bug-typecasting-doesnt-work-when-trying-to-add/10043/4 "2017-11-04T22:25:23Z")

</div>

Hi @Teacher_Mah, I don’t have access to my iPhone at the moment, but you could try something like this?

 ![](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/2X/2/20e254b27c4800e8f3191541b6dd0a0400e80bb9.png)

My idea is that passing your number variables through some other Math blocks will imply that the compiler should treat them as numbers rather strings.

Thanks for pointing this out though, hopefully there will be a “numbers only” option added to the `TextInput` in the future.

---

<div class="post-metadata">

**Author:** ![Teacher\_Mah](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Teacher\_Mah](https://community.thunkable.com/u/Teacher_Mah)\
**Post date:** [November 6, 2017, 5:01pm UTC](https://community.thunkable.com/t/bug-typecasting-doesnt-work-when-trying-to-add/10043/5 "2017-11-06T17:01:28Z")

</div>

Thanks! This is a good workaround 🙂

---

<div class="post-metadata">

**Author:** ![domhnallohanlon](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/domhnallohanlon/32/29554_2.png) [@domhnallohanlon](https://community.thunkable.com/u/domhnallohanlon)\
**Post date:** [November 6, 2017, 5:08pm UTC](https://community.thunkable.com/t/bug-typecasting-doesnt-work-when-trying-to-add/10043/6 "2017-11-06T17:08:10Z")

</div>

Did you test it? Does it work??

---

<div class="post-metadata">

**Author:** ![Teacher\_Mah](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Teacher\_Mah](https://community.thunkable.com/u/Teacher_Mah)\
**Post date:** [November 6, 2017, 5:28pm UTC](https://community.thunkable.com/t/bug-typecasting-doesnt-work-when-trying-to-add/10043/7 "2017-11-06T17:28:40Z")

</div>

Yes it does - the calculation works. I thought I tried the round option earlier but regardless, “round” will force the variable as a number.

---

<div class="post-metadata">

**Author:** ![domhnallohanlon](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/domhnallohanlon/32/29554_2.png) [@domhnallohanlon](https://community.thunkable.com/u/domhnallohanlon)\
**Post date:** [November 9, 2017, 11:50am UTC](https://community.thunkable.com/t/bug-typecasting-doesnt-work-when-trying-to-add/10043/8 "2017-11-09T11:50:20Z")

</div>

Try this new feature::

> [@Numbers in TextInput/Label](http://community.thunkable.com/t/numbers-in-textinput-label/10282/2):
>
> Hi there. We just released the ability to set your Text Input keyboard to Numbers Only – hopefully this helps you with your Math functions. Albert

---

<div class="post-metadata">

**Author:** ![Teacher\_Mah](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Teacher\_Mah](https://community.thunkable.com/u/Teacher_Mah)\
**Post date:** [November 13, 2017, 7:25pm UTC](https://community.thunkable.com/t/bug-typecasting-doesnt-work-when-trying-to-add/10043/9 "2017-11-13T19:25:35Z")

</div>

Changing the input fields to ‘numeric’, and leaving the code without the rounding **does not** work, and continues to join the numbers as text (1 + 2 = 12).

However, the original solution using “round” **does** work.

 ![](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/2X/1/1cb09c14c7214109402d501d17358cb0bdce6032.png)

---

<div class="post-metadata">

**Author:** ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)\
**Post date:** [November 8, 2024, 12:06pm UTC](https://community.thunkable.com/t/bug-typecasting-doesnt-work-when-trying-to-add/10043/10 "2024-11-08T12:06:00Z")

</div>


