AnsweredAssumed Answered

AF uses Banker's Rounding

Question asked by Hoa.Tram on Jan 9, 2020
Latest reply on Jan 10, 2020 by Rick_Davin_3.0

One of our field guys noticed some odd behavior when setting up some analytics and notifications.  One of the tags we have divides the value of one (Int32) tag with another and the result is placed in a third Int32 tag.  Think A = 3, and B = 2.  The result 1.5 is placed into the third tag as 2 instead of truncating the decimal like what he was expecting.  I suspected that OSI was using banker's rounding (rounds to the nearest *even* number at the midpoint) to determine what result gets stored.  I verified this by setting A = 5 and B = 2, and sure enough, the result was 2 stored into the third Int32 tag. 

 

I'm assuming that, underneath the hood, OSI is doing floating point division and using something along the lines of Convert.ToInt32() in .NET instead of straight up integer division or Int32 casting to achieve this result.

 

My question is whether this is intentional behavior?  Or would you view it as a bug where this behavior may change in some future release?  Also, is this behavior consistent across OSI's product stack (e.g. with PEs)?

 

For now, to get the result we want, we explicitly force a floating point division of the inputs and then take the floor of the result.  I'm not sure if this will work with other products in the OSI stack.

Outcomes