Integers [AX 2012]
Updated: September 21, 2011
Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012
Integers are numbers without decimals. X++ has two integer types:
-
int, which is 32 bits wide
-
int64, which is 64 bits wide
Integers are used especially as control variables in repetitive statements or as indexes in arrays.
|
integer declaration |
= |
int | int64 Variable { , Variable } ; |
|
variable |
= |
identifier [ option ] |
|
option |
= |
// Declaration of an integer variable, i int i; // Declaration of two int64 variables int64 i1, i2; // An integer variable is initialized to the value 100 int i3 = 100; // Declaration of a dynamic array of integers int i4[];
Caution
|
|---|
|
If you try to assign the largest integer plus 1 to an int64, you will get the wrong result. This is because it is interpreted as a 32-bit number, and therefore the number is wrapped round and stored as -2,147,483,647 instead. To prevent this, add a "u" to the end of the number, for example: int64 i = 0x8000 0000u (0x8000 0000 is 2,147,483,648). |
Integers can be used in all expressions, and relational operators and arithmetic operators can be applied. For example:
void element()
{
// Two integer variables are declared and initialized
int i = 1, j = 2;
;
// j is assigned the result of j + ((i + i) DIV 2)
j +=(i + i) div 2;
// This results in: j=3
if (j>2)
{
print "J is greater than 2";
}
else
{
print "J is NOT greater than 2";
}
}
|
Keywords |
int, int64 |
|
Size |
32 bits or 64 bits |
|
Scope of data type |
[-2,147,483,648 : 2,147,483,647] or [-9,223,372,036,854,775,808 : 9,223,372,036,854,775,808] |
|
Default value |
0 |
|
Implicit conversions |
Automatically converted to real, boolean, and enum |
|
Explicit conversions |
str2int, int2str, str2int64, int642str |
Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.
Caution