December 07, 2012

Make Absolut Function for Data Type Integer in AX

Actually to use absolute function in AX, we can use function "abs". However this function is for data type "Real". If we use it for data type "Integer", it will appear warning for Lossless precission. To avoid it, we can make own function in class global in AX like this code :

static int absInt(int _Input)
{
    //Added by : Andik-WCS on Dec 6th 2012
    if(_Input >= 0)
    {
        return _Input;
    }

    else
    {
        return _Input - 2*_Input;
    }
}


to use it :
absValue = absInt(-100);
it will return value 100.

1 comments:

Post a Comment