-
Couldn't find anything on this one - When reading a REAL tag, I get a number back that is slightly off - for example:
I also noticed the responses in the docs (basic read/write examples), your response for the real was |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yeah that is because of how floating points are represented in binary. Here is a doc that explains more about how Python handles floats. The plc is doing some rounding to show you the closest approximate value and python does the same when you type |
Beta Was this translation helpful? Give feedback.
Yeah that is because of how floating points are represented in binary. Here is a doc that explains more about how Python handles floats. The plc is doing some rounding to show you the closest approximate value and python does the same when you type
.1
or1/10
. But, since I'm using the struct module to unpack the floating point value from bytes, I don't think it will do the rounding for the string representation. One thing I could do is change the repr for the Tag objects to round to a certain number of decimal places, but then it would be to a fixed number of decimals for every object.