# \[Solved\] Factorial Math Function

**URL:** <https://community.thunkable.com/t/solved-factorial-math-function/327906>\
**Category:** Questions about Thunkable X\
**Tags:** solved, beginner\
**Created:** [November 19, 2019, 3:44pm UTC](https://community.thunkable.com/t/solved-factorial-math-function/327906 "2019-11-19T15:44:51Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![franckled](https://avatars.discourse-cdn.com/v4/letter/f/58956e/32.png) [@franckled](https://community.thunkable.com/u/franckled)\
**Post date:** [November 19, 2019, 3:44pm UTC](https://community.thunkable.com/t/solved-factorial-math-function/327906/1 "2019-11-19T15:44:51Z")

</div>

Hi all,  
I try to create a loop to calculate Factorial math function…  
It works sometimes but the mathematical calculation can change and I don’t know why. May be it’s due to the type of the variable (numeric vs text) ?? Is it possible to change the text variable into a numeric variable to be sure that the calculation is good ?  
Do you have another idea why the calculation can change ?  
Thanks…

In the screen you can see the loop to calculate the factorial of the sum 1, 2, 3 and 4.  
And the result…

The sum of the row 1 is 2 (Tot A = 1 + 1) and correct and the factorial gives 6  
The sum of the row 2 is 4 (Tot B = 2 + 2) and correct but the factorial gives 360 !!!

 ![24](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/5/f5d7ce1a9498438607f454c4194ee51ee770bf37.png) ![15](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/e/d/edecae5853fca876a1f3a36416c94846455c8d91.png)

---

<div class="post-metadata">

**Author:** ![CBVG](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/cbvg/32/32401_2.png) [@CBVG](https://community.thunkable.com/u/CBVG)\
**Post date:** [November 19, 2019, 6:09pm UTC](https://community.thunkable.com/t/solved-factorial-math-function/327906/2 "2019-11-19T18:09:32Z")

</div>

If you want to ensure that a text variable is interpreted as a number, add 0 to it. That will convert the value to a scalar.

That said, with your loops, you keep multiplying a variable (‘ap’, ‘bp’, ‘cp’, etc) by a coefficient and assigning it back to itself. The question is: how do you ensure that “ap” does not have a pre-existing value? Do you start by _initializing_ them to 1 before multiplying with anything?

---

<div class="post-metadata">

**Author:** ![franckled](https://avatars.discourse-cdn.com/v4/letter/f/58956e/32.png) [@franckled](https://community.thunkable.com/u/franckled)\
**Post date:** [November 19, 2019, 6:47pm UTC](https://community.thunkable.com/t/solved-factorial-math-function/327906/3 "2019-11-19T18:47:18Z")

</div>

Hi  
Thanks for your answer.  
Yes I have a Function before to run the loop Which initialize each variable to 1 ☹

---

<div class="post-metadata">

**Author:** ![actech](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@actech](https://community.thunkable.com/u/actech)\
**Post date:** [November 19, 2019, 7:14pm UTC](https://community.thunkable.com/t/solved-factorial-math-function/327906/4 "2019-11-19T19:14:22Z")

</div>

Hi,

Get Factorial

 ![%D0%B8%D0%B7%D0%BE%D0%B1%D1%80%D0%B0%D0%B6%D0%B5%D0%BD%D0%B8%D0%B5](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/6/9608da96e204300cdeb86bd5c01d8032a474566f.png)

---

<div class="post-metadata">

**Author:** ![franckled](https://avatars.discourse-cdn.com/v4/letter/f/58956e/32.png) [@franckled](https://community.thunkable.com/u/franckled)\
**Post date:** [November 19, 2019, 7:29pm UTC](https://community.thunkable.com/t/solved-factorial-math-function/327906/5 "2019-11-19T19:29:26Z")

</div>

Whaouhhhhh  
Respect 😳  
I will try this.

---

<div class="post-metadata">

**Author:** ![franckled](https://avatars.discourse-cdn.com/v4/letter/f/58956e/32.png) [@franckled](https://community.thunkable.com/u/franckled)\
**Post date:** [November 20, 2019, 9:09am UTC](https://community.thunkable.com/t/solved-factorial-math-function/327906/6 "2019-11-20T09:09:43Z")

</div>

Hello,  
May be I missed something… When I try to run your procedure, the result is one… Where is my mistake ?  
TEFA is my Input field  
label44 my label  
ap is my variable (-\> number)

 ![50](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/d/d/dd5a0cc5dec315fb795294699fbd19b37cb72342.png)

---

<div class="post-metadata">

**Author:** ![actech](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@actech](https://community.thunkable.com/u/actech)\
**Post date:** [November 20, 2019, 9:11am UTC](https://community.thunkable.com/t/solved-factorial-math-function/327906/7 "2019-11-20T09:11:45Z")

</div>

Hello,

Instead of variables from function parameters, you use problem blocks of global variables.

---

<div class="post-metadata">

**Author:** ![franckled](https://avatars.discourse-cdn.com/v4/letter/f/58956e/32.png) [@franckled](https://community.thunkable.com/u/franckled)\
**Post date:** [November 20, 2019, 9:15am UTC](https://community.thunkable.com/t/solved-factorial-math-function/327906/8 "2019-11-20T09:15:25Z")

</div>

I’m sorry, I don’t understand…  
Need I use another variable ? AP is not the good one ?

---

<div class="post-metadata">

**Author:** ![actech](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@actech](https://community.thunkable.com/u/actech)\
**Post date:** [November 20, 2019, 9:16am UTC](https://community.thunkable.com/t/solved-factorial-math-function/327906/9 "2019-11-20T09:16:17Z")

</div>

![%D0%B8%D0%B7%D0%BE%D0%B1%D1%80%D0%B0%D0%B6%D0%B5%D0%BD%D0%B8%D0%B5](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/3/03ff573bbf860d3353d03956c9937b7e793fc019.png)

---

<div class="post-metadata">

**Author:** ![franckled](https://avatars.discourse-cdn.com/v4/letter/f/58956e/32.png) [@franckled](https://community.thunkable.com/u/franckled)\
**Post date:** [November 20, 2019, 9:23am UTC](https://community.thunkable.com/t/solved-factorial-math-function/327906/12 "2019-11-20T09:23:51Z")

</div>

I see the getfactor different… This module is not in the function one ?

☹  
Terrible… I will try…  
Sorry

It’s ok now…  
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 20, 2019, 10:05am UTC](https://community.thunkable.com/t/solved-factorial-math-function/327906/13 "2019-11-20T10:05:06Z")

</div>

@franckled, I’ve merged you 3 responses into a single post.

For future reference, if you have updates or amendments to make to a post in the community, please use the Edit button ✏ on your post.

---

<div class="post-metadata">

**Author:** ![franckled](https://avatars.discourse-cdn.com/v4/letter/f/58956e/32.png) [@franckled](https://community.thunkable.com/u/franckled)\
**Post date:** [November 20, 2019, 10:06am UTC](https://community.thunkable.com/t/solved-factorial-math-function/327906/14 "2019-11-20T10:06:26Z")

</div>

ok

---

<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, 11:43am UTC](https://community.thunkable.com/t/solved-factorial-math-function/327906/15 "2024-11-08T11:43:01Z")

</div>


