Topic: DMD0129

TOINT - Convert to Integer


This instruction can only be used in the Expression parameter of the Calculate Expression (MATH) instruction.

 

The Convert to Integer (TOINT) function will convert the input real number to an integer. The value will not be rounded. The range of acceptable input values is any positive or negative real number.

 

The expression parameter consists of all the text between the bounding parentheses. Any expression parameter can be a constant value, a bit or numeric memory location, an arithmetic expression, and/or mathematical function or other expressions up to a maximum of 1024 characters. Expressions can be nested, so use of parentheses is recommended to ensure proper evaluation order.

 

Using the Math box example to the right:

 

  • If R0 = 3.14159 the result in D0 would be 3
     

  • If R0 = -3.14159 the result in D0 would be -3

 

To force integer math calculations on subsequent math operations, denote the real expression to it's 32-bit 2's complement integer equivalent. For information on promotion and demotion see the help topic for the  MATH - Calculate Expression instruction. Use the ROUND() function to round the result of the expression to the nearest value instead of truncating the value.

 


See Also:

 


Related Topics:

 


Rung Example: