Math Floor Scripting Issues

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.

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)

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.

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.

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

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

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.

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

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!)

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.

2 Likes

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.

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.