BASIC convert FLOAT to INT


Hi team!
i need to copy the integer part of a S73&400 float tag to a MEM integer tag:
my S73&400 float tag is PlcStatusTag
my MEM int tag is IntStatusTag

if PlcStatusTag=1.0 the IntStatusTag must be setted to 1
if PlcStatusTag=1.2 the IntStatusTag must be setted to 1
if PlcStatusTag=23.4 the IntStatusTag must be setted to 23

is there any DIV or TRUNC or INT funcion ?


When you truncate it, do you always want it to round down?

Or if it’s something like 1.9 do you want it to round up to 2?


i have both case


Here’s some BASIC IDE code I wrote to be able to do this

  • Test is the real floating point value that is being read from the PLC
  • Test2 is a tag that is set to be an Integer type
  • b is just a variable that is used to take the difference between the real and integer value since by default if you read in a real value as an integer it will just cut off the decimal and do no rounding.

For example: if test@ = 1.7, then test2@ will equal 1 and will cause b to equal 0.7

OnChange “test”, “@OutTest()”
b = 0
Function OutTest()
Test2@ = test@
b = Test@ - Test2@
if b >= 0.5 then
test2@ = test2@ + 1
test2@ = test@
Print test2@


thank you for the code!

now the problem is that my tag name contains () , for example PlcStatusTag(0) or IntStatusTag(0), so i cant use IntStatusTag(0)@=PlcStatusTag(0)@

i must use SETIO “IntStatusTag(0)”,“PlcStatusTag(0)”

i have no debugging errors but the SETIO seem that doesn’t convert from float to int



Would it be possible to change the name of your tag to IntStatusTag0 without the parentheses?


unfortunately no is not possible…



unfortunately no, i must use the ( )



Can you try and do something like the following?

b = getio “PlcStatusTag(0)”


the problem is to assign the value of a float tag into a int tag ;
if i use SETIO “IntStatusTag(0)”,“PlcStatusTag(0)” , the IntStatusTag(0) is set forever to a wrong value, if you change the value of PlcStatusTag(0), the IntStatusTag(0) value remain at the first value

you can try to reproduce it using two mem tag:

in basic i use this script


if you set manually the value of the float tag (in this case 5.7), the output tag is setted to 1082101684 and then remain setted to this value.

no errors in console or in Log

others way to set the IntStatusTag(0) generates debug errors


I was getting that error when I was trying to use a second value with the parentheses, but I was able to get around that by using a different internal tag with an int type.

Try this

OnChange “test”, “@OutTest()”
b = 0
Function OutTest()
Test2@ = test@
b = Test@ - Test2@
If b >= 0.5 Then
test2@ = test2@ + 1
Setio “IntStatusTag(0)”,test2@
test2@ = test@
Setio “IntStatusTag(0)”,test2@
Print test2@