There is no Float2Int instruction in the instruction set for CLICK PLCs from AutomationDirect*, but it is not difficult to convert floating point values to integers with that series. There are two methods I use: rounding with the MATH instruction and truncating with the COPY instruction. With either method, the key is to specify an integer memory location for the destination. This automatically casts the result as an integer.
Rounding with the MATH instruction
To round a value to the nearest whole number or integer when converting floating point values, use the MATH instruction to add 0.5 to the value. Then store the result in an integer register (the memory locations prefixed with DD or DS, see also CLICK PLC Data Types) to truncate the fractional portion.
For example, rounding 6.2 works like this: 6.2 + 0.5 = 6.7 which is then truncated to 6 when stored as an integer:
And 6.5 + 0.5 = 7.0, which truncates to 7:
The comparison instructions (DF99 > 0) at the beginning of the above rungs are only for demonstration purposes, to display the value of DF99.
Truncate using the COPY instruction
If you need to remove the fractional value of a floating point value without rounding, COPY the floating point value to an integer register and, if necessary, copy it back again. For the example below, a value of 6.8 is copied into floating point memory location DF99 in the first COPY instruction. In reality, this value might have come from a calculation. The second COPY instruction truncates the fractional 0.8 portion of the original value. It does this because an integer memory location, DS3, is specified as the Destination. So the fractional portion has nowhere to go. If the truncated value needs to be in the original floating point memory location, copy the value back from the integer memory location to the floating point memory location.
Note that the screenshot of the truncation example is a little misleading because it shows the values in the memory locations after the rung has been processed by the PLC. So the first COPY instruction shows DF99 containing 6 already, even though DF99 does not contain this value until the third COPY instruction.
If you are using a Do-More PLC, see the ROUND() function of the MATH instruction.
* This site is not affiliated with AutomationDirect.