# Math Floor Scripting Issues

**URL:** <https://forum.inductiveautomation.com/t/math-floor-scripting-issues/91488>\
**Category:** Ignition\
**Tags:** scripting, perspective\
**Created:** [June 6, 2024, 2:48pm UTC](https://forum.inductiveautomation.com/t/math-floor-scripting-issues/91488 "2024-06-06T14:48:42Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ColeS](https://avatars.discourse-cdn.com/v4/letter/c/65b543/32.png) [@ColeS](https://forum.inductiveautomation.com/u/ColeS)\
**Post date:** [June 6, 2024, 2:48pm UTC](https://forum.inductiveautomation.com/t/math-floor-scripting-issues/91488/1 "2024-06-06T14:48:42Z")

</div>

I have a script that I have the math.ceil() instruction working in yet I cannot get math.floor() to work. Does anyone know why? Using a label with the expression I was able to use just floor to get the values I want but when I go to do it in the python script, I am only getting a float value.

```python
def runAction(self):
	import math
	if self.view.custom.PB < 1:
		if temp1 == 0:
			i = len(self.props.instances)
			while i < math.ceil(self.view.custom.INV * self.view.custom.PB):
				instance = {
				"INV": int(i+1),
				}
				self.props.instances.append(instance)
				i += 1
		elif temp1 > 0:
			i = math.floor((self.view.custom.INV*self.view.params.PB)-self.view.custom.INV)
			instance = {
			"INV" : int(i+1)
			}
			self.props.instances.append(instance)

```

---

<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:** [June 6, 2024, 3:08pm UTC](https://forum.inductiveautomation.com/t/math-floor-scripting-issues/91488/2 "2024-06-06T15:08:58Z")

</div>

What error are you getting? Try adding some logging to print to the log the values the floor function is being passed to see if maybe there's an issue somewhere.

---

<div class="post-metadata">

**Author:** ![ColeS](https://avatars.discourse-cdn.com/v4/letter/c/65b543/32.png) [@ColeS](https://forum.inductiveautomation.com/u/ColeS)\
**Post date:** [June 6, 2024, 3:12pm UTC](https://forum.inductiveautomation.com/t/math-floor-scripting-issues/91488/3 "2024-06-06T15:12:41Z")

</div>

It isn't an error exactly it just isn't working. I am getting floats like 1.34, 1.68, 2.02 instead of 1, 1, and 2.

---

<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:** [June 6, 2024, 3:14pm UTC](https://forum.inductiveautomation.com/t/math-floor-scripting-issues/91488/4 "2024-06-06T15:14:11Z")

</div>

Check that none of your values are strings. Is `self.view.params.PB` correct or should it be `self.view.custom.PB`?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 6, 2024, 3:16pm UTC](https://forum.inductiveautomation.com/t/math-floor-scripting-issues/91488/5 "2024-06-06T15:16:02Z")

</div>

Why are you using `int()` on what are integer types?

---

<div class="post-metadata">

**Author:** ![ColeS](https://avatars.discourse-cdn.com/v4/letter/c/65b543/32.png) [@ColeS](https://forum.inductiveautomation.com/u/ColeS)\
**Post date:** [June 6, 2024, 3:18pm UTC](https://forum.inductiveautomation.com/t/math-floor-scripting-issues/91488/7 "2024-06-06T15:18:02Z")

</div>

Those are two different parameters one is being passed in from a selection box on another screen and the other is the max number of PB instances.

---

<div class="post-metadata">

**Author:** ![ColeS](https://avatars.discourse-cdn.com/v4/letter/c/65b543/32.png) [@ColeS](https://forum.inductiveautomation.com/u/ColeS)\
**Post date:** [June 6, 2024, 3:19pm UTC](https://forum.inductiveautomation.com/t/math-floor-scripting-issues/91488/8 "2024-06-06T15:19:32Z")

</div>

I did that after running into this issue thinking I could force it from a float to a string but that did not help.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 6, 2024, 3:20pm UTC](https://forum.inductiveautomation.com/t/math-floor-scripting-issues/91488/9 "2024-06-06T15:20:47Z")

</div>

Can you post the data you've got and what result you want. There's probably a simpler way to do it. I think you said before that you're new to Python. (I'm no guru but sometimes I can make things 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:** [June 6, 2024, 3:21pm UTC](https://forum.inductiveautomation.com/t/math-floor-scripting-issues/91488/10 "2024-06-06T15:21:29Z")

</div>

Then I would say go back and log values and data types as I suspect somewhere a value is being passed as a string instead of a float or integer and causing it all to break. I've seen it happen before.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [June 6, 2024, 3:40pm UTC](https://forum.inductiveautomation.com/t/math-floor-scripting-issues/91488/11 "2024-06-06T15:40:31Z")

</div>

I would expect your script to be failing completely because `temp1` is never defined. Check your Gateway logs to see if the script is reporting errors.

---

<div class="post-metadata">

**Author:** ![ColeS](https://avatars.discourse-cdn.com/v4/letter/c/65b543/32.png) [@ColeS](https://forum.inductiveautomation.com/u/ColeS)\
**Post date:** [June 6, 2024, 3:49pm UTC](https://forum.inductiveautomation.com/t/math-floor-scripting-issues/91488/12 "2024-06-06T15:49:11Z")

</div>

I have other code that I did not include to avoid further confusion, I know all of that works. The definitions were all included in that chunk of data. I just swapped out the tags for actual values and found out it was the string issue. Everything is now working as expected.
