Marten Posted May 7, 2020 Report Share Posted May 7, 2020 Hi, I've a routinewhitch add 0.1 every 100ms to variable counter(Real). And every time machine is idle it is reset to 0. When running this the counter value is not correct, it is 1.1001 9.9999 , but adding 0.1 and no other value this shouldn;t be possible. Now i add every 100ms a 1 to an integer, then convert it to real, then multiply *0,1, and this works, Quote Link to comment Share on other sites More sharing options...
AlexUT Posted May 7, 2020 Report Share Posted May 7, 2020 Hi Marten, This is a Real rounding error when you make sequential operations. Use integer and convert it one-time is a right solution (like you doing). B.R. Quote Link to comment Share on other sites More sharing options...
Marten Posted May 7, 2020 Author Report Share Posted May 7, 2020 Thanks for you answer, I would like to know more, I haven't seen this in for instance Omron or Siemens. Why is this happening? In general if I want to use a calculation where the output is being used and linked at the input, i cannot use this? What if we use Real on a measured value, what is max rounding error then? Quote Link to comment Share on other sites More sharing options...
MVP 2022 Flex727 Posted May 7, 2020 MVP 2022 Report Share Posted May 7, 2020 There is no reason to use floating point numbers in this situation. No digital computer or PLC can handle floating point numbers perfectly and it's best to avoid them when possible. This is due to the conversion from decimal to binary and then back to decimal. Without infinite precision, which is of course impossible, there will be rounding errors which can be significant. In your case, use integers (add 1, not 0.1) and display the number with one decimal place. If you need to perform calculations, just keep track of where the decimal place is and make sure it matches on all the other numbers in the calculation. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.