Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger


Thursday, September 8, 2011

Integer declaration example code in Microsoft Dynamics AX

Integers are numbers without decimals. They are divided into two separate data types in AX: the int which is a 32 bit integer, and the int64 which is a 64 bit integer. The int data type ranges from -2,147,483,647 to 2,147,483,647. The int64 ranges from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,808, which should be enough for most of us.

You can do any kind of arithmetic with the integers directly in the code, such as the multiplication in the next example that will print Carz Inc have 24 cars in total.

static void Datatypes_integer1(Args _args)
{
int carsInEachOffice;
int offices;
;
carsInEachOffice = 6;
offices = 4;
print strfmt("Carz Inc have %1 cars in total",
carsInEachOffice *
offices);
pause;
}

Dividing two integers will result in a real number unless you are returning the value to an integer. This means that dividing 24/4 gives the result 6.00, but returning the result to an integer and printing it results in 6 as you will see in the next example.
static void Datatypes_integer2(Args _args)
{
int x = 24;
int y = 4;
int res = x/y;
;
// Prints a real value
print strfmt("%1 / %2 = %3", x, y, x/y);
// Automatically type casted to int
// to print the integer value
print strfmt("%1 / %2 = %3", x, y, res);
pause;
}

No comments:

Post a Comment

Archives