Here's a simple function to round any positive floating-point number to the nearest whole number.
DEFINE_FUNCTION Integer Round (Float fInput)
{
Return TYPE_CAST (fInput + 0.5);
}
It works by taking advantage of the characteristics of NetLinx 'TYPE_CAST' operator and integers. When a float is type cast into an integer, the decimal portion of the original number is dropped. By first adding 0.5 to the number, this function ensures that all numbers get rounded to the nearest whole. (1/2 gets rounded up, as is customary.)
Example:
fTest = 2.63
nVar = Round (fTest) // nVar will be set to 3