Jump to content

Data Real Inaccurate


Marten

Recommended Posts

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,

 

Link to comment
Share on other sites

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? 

Link to comment
Share on other sites

  • MVP 2023

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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

This site uses cookies. By clicking I accept, you agree to their use.