| REBOL 3 Docs | Guide | Concepts | Functions | Datatypes | Errors |
| TOC < Back Next > | Updated: 6-Feb-2009 Edit History |
The integer! datatype includes 32-bit positive and negative numbers and zero. Unlike decimal numbers, integers do not contain a decimal point.
Integer values consist of a sequence of numeric digits. A plus (+) or minus (-) immediately before the first digit indicates sign. (There cannot be a space between the sign and the first digit.) Leading zeros are ignored.
0 1234 +1234 -1234 00012 -0123
Do not use commas or periods in integers. If a comma or period is found within an integer it is interpreted as a decimal value. However, you can use a single quote (`) to separate the digits in long integers. Single quotes can appear anywhere after the first digit in the number, but not before the first digit.
2'147'483'647
Integers span a range from -2147483648 to 2147483647.
Use the to-integer function to convert a string!, logic!, decimal!, or integer! datatype to an integer:
probe to-integer "123"
123
probe to-integer false
0
probe to-integer true
1
probe to-integer 123.4
123
probe to-integer 123.8
123
probe to-integer -123.8
-123
If a decimal and integer are combined in an expression, the integer is converted to a decimal:
probe 1.2 + 2
3.2
probe 2 + 1.2
3.2
probe 1.01 > 1
true
probe 0 < .001
true
Use integer? to determine whether a value is an integer! datatype.
probe integer? -1234
true
Use the form, print, and mold functions with an integer argument to print a integer value as a string:
probe mold 123
123
probe form 123
123
print 123
123
Integers that are out of range or cannot be represented in 32 bits are flagged as an error.
| TOC < Back Next > | REBOL.com - WIP Wiki | Feedback Admin |