Scripting and division operator "/"

I'm using Ignition version 8.1.24 and was debugging some scripting in the project script library
and noticed when converting DegF to DegC the results were 0???

Testing the code in the script console resulted in same results, then I tested the following

image

Notice the 2 division operator returned the same rounded results!

Safe to assume that the standard division operator "/" should've returned a floating number, 2.6667
Explains why in the scripting code the formula (DegF-32) * (5/9) was equal to 0, the (5/9) result is rounding to 0 instead of 0.5555.

I don't recall a configuration that would cause the rounding.

Make one or both of those a float, e.g.

8.0/3
8/3.0
8.0/3.0

What you're seeing is standard behavior for integer division.

3 Likes

Oh..duh....never thought about that...

Or
8 * 1.0 / 3
myInt * 1.0 / 3
will force the variable into a float.
It seems a bit weird to me that Python works that way.

And keep that in mind when your using the Multi-Instance Wizard! There is no 'floor' division operator-- that rounding up when trying to divide 100 tags into groups of 4 will get you every time!