Jump to content

Real Value Modified when Written in Data Table


Recommended Posts


I am new to this forum so bear with me if I am not respecting some of your rules.

I have encountered an issue working with data table. 

I m writing a real value to a data table, but the value displayed on the HMI is different from the original value.

you can see in the attached images what I am describing.

How can I prevent this ?

My controller is a unistream USC B5 TR22.

Thank You in advance

scr_sht_val on hmi view.jpg

scr_sht_val online view.jpg

Link to comment
Share on other sites

That's a difference of 0.000038467575848% .

How accurate are you expecting ?

What data types are they set to?

If I need accuracy in the numbers I always collect it with the highest resolution data type (16-bit, 32-bit, 64-bit) I can, then I force the values to a resolution using a round/truncate function that fits the requirements.   Example:   My required scaling is 0.00 - 100.00.   I'll carry my collection out to 123.123456 then round/truncate to 123.1234-> xxx.xx 

Link to comment
Share on other sites

  • MVP 2023

+1 on what @dierkens says.

That is the downside of a REAL value.  They are way more precise than most of us need.  

Have you considered using integers for everything?  They are much more predictable and manageable and a Long type can handle almost any number occurring in our world.  I only use REALs when complex calculations are involved, like trig functions.  

Joe T.

Link to comment
Share on other sites

Thank you both @Joe Tauser and @dierkens

I am using Real data type because I have to keep track of liters reading input by the operator. It has to be REAL data type since the reading is of the form 12345,12.

But now with the inaccuracy of the REAL data type, summing up these values does not reflect the actual real world situation.

@dierkens did mention a  difference of 0.000038467575848% but i have seen value like 10.7 be saved as 10.625.

Are there rounding functions I can use to solve this issue? 

Thanks again

Link to comment
Share on other sites

  • MVP 2023
3 hours ago, job517 said:

It has to be REAL data type since the reading is of the form 12345,12.

That is not true. It is best to use integers for this type of data. The HMI variables allow for an implied decimal. You simply set it up for the 2 decimal places you need and keep track of where the decimal point is if there are any subsequent calculations. In your example case, be sure you use a 32-bit integer, as the actual number in the register will be 1234512 which is too large for a 16-bit integer.

Once you learn and understand using integers with implied decimals you will find that many arithmetic operations in your PLC software will be greatly improved.

  • Thanks 1
Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...