# Convert REAL to INT

• Hi!

I get a numerical value from the PLC in a REAL format but in order to use the value as index for a FOR/ENDFOR-loop the value must be an INTEGER.

How can I convert the REAL-value to an INT-value in the robot (LR-MATE 200 with plus-controller)?

Is it enough to move it to another [R] register or is there an instruction that must be used?

Thank you!

Try using the DIV command to convert the Real number to an Integer. The DIV command is for Integer division and will return only the quotient. R[1] is Real, R[2] is new Integer. R[2]=R[1] DIV 1 This will divide R[1] by 1 and will set R[2] to the Integer value of R[1].

• Try using the DIV command to convert the Real number to an Integer. The DIV command is for Integer division and will return only the quotient. R[1] is Real, R[2] is new Integer. R[2]=R[1] DIV 1 This will divide R[1] by 1 and will set R[2] to the Integer value of R[1].

This is a good suggestion.
Also, adding before division +0.5 to positive value or -0.5 to negative one, will result in correctly rounded integer, instead of truncated.

• Tell the PLC programmer to send it as an integer. If they are using explicit messaging this is done by changing class to either 6c or 6b.

• Thank you for your help and suggestions. In this case it will be easier, for many reasons, to fix this myself in the robot. So I will first try the division tactic.

Thank you!

• Runis86

Why not do it on the PLC like hermann and HawkME mentioned ?

Yes, you can do it with the robot but is going to add a bit of processing time.

What is the PLC guy telling you ? I just want to have a laugh

Retired but still helping

• The main reason is that we do not have the plc programmer in house. And we have a bunch of machines rolled out around the world.

We have the knowledge and possibilities to adjust on the robot side of the application but not on the plc side. So even though it would be easier to change the plc program I really prefer how to do this on the robot side in case we need to do this on a machine on the other side of the world.

• Hi! As an update i did the following to solve the problem.

I used the division function accordingly:

R[1]=R[1] DIV 1

So the register can be equal to itself divided by 1.

Thank you for your support!

## 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!