Macros and the IBM CognosScript Language  7.5.0
IBM CognosScript Statements and Functions >

Int Function

Description

Returns the integer part of a number.

Syntax

Int( number )

where:

is:

number

Any numeric expression.

Comments

For positive numbers, Int removes the fractional part of the expression and returns the integer part only. For negative numbers, Int returns the largest integer less than or equal to the expression. For example, Int (6.2) returns 6; Int(-6.2) returns -7.

The return type matches the type of the numeric expression. This includes Variant expressions that will return a result of the same vartype as input except vartype 8 (string) will be returned as vartype 5 (double) and vartype 0 (empty) will be returned as vartype 3 (long).

Example

This example uses Int to generate random numbers in the range between the ASCII values for lowercase a and z (97 and 122). The values are converted to letters and displayed as a string.

Sub main
	Dim x as Integer
	Dim y
	Dim str1 as String
	Dim letter as String
	Dim randomvalue
	Dim upper, lower
	Dim msgtext, newline
	upper=Asc("z")
	lower=Asc("a")
	newline=Chr(10)
	For x=1 to 26
		Randomize timer() + x*255
		randomvalue=Int(((upper - (lower+1)) * Rnd) _
               +lower)
		letter=Chr(randomvalue)
		str1=str1 & letter
'Need to waste time here for fast processors
		For y=1 to 1500
		Next y
	Next x
	msgtext="The string is:" & newline
	msgtext=msgtext & str1
	MsgBox msgtext
End Sub

See Also

Exp Function

Fix Function

Log Function

Rnd Function

Sgn Function

Sqr Function