Click or drag to resize

Integer Function

Truncate or floor a number with decimal digits to a whole number.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.07
 FUNCTION Integer(
	nValue AS USUAL
View Source


Type: Usual
The number to truncate or floor.

Return Value

Type: Usual
The whole number to the left of the decimal point.  Since both <uValue> and the return value are data type USUAL, you are not limited to the size of an integer.
Integer() converts a numeric value to an integer by taking the floor of the number. Note – this is not the same as truncation except for positive integers — it is not rounding.  Integer() is useful in operations where the decimal portion of a number is not needed.  See "Operators and Expressions" in the Programmer's Guide for information on type casting. Note that a loss of precision on floating numbers might be significant.  For example, you might not know that a number is internally represented as 0.99999999999999999, because, when that number is displayed with QOut() or passed to the Str() function, internal rounding returns a value of 1.0. When a number like that is passed to the Integer() function, however, its decimal portion is truncated and a value of zero is returned.  If this is not what you had intended, you can use Round(<nValue>, 0) instead of Integer().
Tip Tip
Integer() is the same as the Int() function in CA-Clipper, but INT is a reserved word in X#.  Under X#, Int() is a conversion operator.  With numbers that are not greater than a short integer, it yields the same results as Integer() and maintains compatibility with CA-Clipper.
These examples demonstrate the results of various invocations of the Integer() function:
? Integer(100.00)                // 100
? Integer(.5)                        // 0
? Integer(-100.75)                // -100
? Integer(-1.2)                // -1
See Also