Function: AsInt
Function: AsInt

Function: AsInt

AsInt ( INPUT )

Returns the integer value of an input value.

Parameters

Parameter Type Description
INPUT VALUE The input value (any type).

Returns

VALUE(INTEGER) The integer value of the input value.

What It Does

This function returns the integer value of the input value or expression. The integer value 0 is returned for values that are not convertible to an integer, such as strings that are not parse-able as integers. Floats are chopped.

If the input value is already an integer, it is returned as-is. This function does not change or convert a value in-place - you must reassign the result.

Example

The type of each of the values are most visible in a trace.

AsInt Example


world
{
	start()
	{
		textln("asInt(true) = "+asInt(true));
		textln("asInt(false) = "+asInt(false));
		textln("asInt(3) = "+asInt(3));
		textln("asInt(5.1) = "+asInt(5.1));
		textln("asInt(5.75) = "+asInt(5.75));
		textln("asInt(\"300\") = "+asInt("300"));
		textln("asInt(\"apple\") = "+asInt("apple"));
		textln("asInt(5.3 + 3.8) = "+asInt(5.3 + 3.8));
		local a = 10.5;
		textln("asInt(a) = "+asInt(a));
		textln("a = "+a);
		quit;
	}
}

Example Result Table

Value Result
BOOLEAN[false] > INTEGER > INTEGER[0]
BOOLEAN[true] > INTEGER > INTEGER[1]
FLOAT[Infinity] > INTEGER > INTEGER[0]
FLOAT[-Infinity] > INTEGER > INTEGER[0]
FLOAT[NaN] > INTEGER > INTEGER[0]
INTEGER[0] > INTEGER > INTEGER[0]
FLOAT[0.0] > INTEGER > INTEGER[0]
INTEGER[10] > INTEGER > INTEGER[10]
INTEGER[3] > INTEGER > INTEGER[3]
FLOAT[10.0] > INTEGER > INTEGER[10]
FLOAT[3.0] > INTEGER > INTEGER[3]
FLOAT[10.5] > INTEGER > INTEGER[10]
FLOAT[3.5] > INTEGER > INTEGER[3]
INTEGER[-10] > INTEGER > INTEGER[-10]
INTEGER[-3] > INTEGER > INTEGER[-3]
FLOAT[-10.0] > INTEGER > INTEGER[-10]
FLOAT[-3.0] > INTEGER > INTEGER[-3]
FLOAT[-10.5] > INTEGER > INTEGER[-10]
FLOAT[-3.5] > INTEGER > INTEGER[-3]
STRING[] > INTEGER > INTEGER[0]
STRING[ ] > INTEGER > INTEGER[0]
STRING[0] > INTEGER > INTEGER[0]
STRING[0.0] > INTEGER > INTEGER[0]
STRING[10] > INTEGER > INTEGER[10]
STRING[3] > INTEGER > INTEGER[3]
STRING[10.0] > INTEGER > INTEGER[10]
STRING[3.0] > INTEGER > INTEGER[3]
STRING[10.5] > INTEGER > INTEGER[10]
STRING[3.5] > INTEGER > INTEGER[3]
STRING[-10] > INTEGER > INTEGER[-10]
STRING[-3] > INTEGER > INTEGER[-3]
STRING[-10.0] > INTEGER > INTEGER[-10]
STRING[-3.0] > INTEGER > INTEGER[-3]
STRING[-10.5] > INTEGER > INTEGER[-10]
STRING[-3.5] > INTEGER > INTEGER[-3]
STRING[apple] > INTEGER > INTEGER[0]
STRING[banana] > INTEGER > INTEGER[0]
STRING[NaN] > INTEGER > INTEGER[0]
STRING[infinity] > INTEGER > INTEGER[0]
LIST[[]] > INTEGER > INTEGER[0]
LIST[[BOOLEAN[true], INTEGER[3], FLOAT[5.0], STRING[orange]]] > INTEGER > INTEGER[0]
×

Modal Header