A blog offering various X++ code snippets and tips for Microsoft Dynamics AX

Tuesday, February 03, 2009

Getting the number of decimal places for an EDT

Sometimes you might need to get the amount of decimal places set on the EDT. This can either be set to 'AUTO', where the decimal places set in the server's regional settings are taken or manually inputted by the developer in the property inspector.

The following is a code snippet of how this can be done, catering for both scenarios mentioned above:


#WinAPI // Used for regional settings

TreeNode treeNode;
Int decimalPlaces;
treeNode = infolog.findNode(#ExtendedDataTypesPath + '\\' + identifierstr(YourEDT));

if (findproperty(treeNode.AOTgetProperties(),#PropertyNoOfDecimals) == #AUTO)
  // get the number of decimals from the regional settings
  decimalPlaces = str2int((WinAPI::getLocaleInfo(#LOCALE_USER_DEFAULT,   #LOCALE_ICURRDIGITS)));
  // get the number of decimals set by the developer in the property inspector
  decimalPlaces = str2int(findproperty(treeNode.AOTgetProperties(),#PropertyNoOfDecimals));

info (int2str(decimalPlaces));

If you any questions or comments e-mail me on: mirko@mirkobonello.com

No comments: