Code based on Mirko Bonello's work: http://dynamicsax-dev.blogspot.com/2009/02/getting-number-of-decimal-places-for.html
str num2strEdt(
real _number, //The real number to convert to a string
int _character = 0, //The minimum number of characters required in the text.
ExtCodeValue _edt, //The EDT to be used as basis for required number of decimal places.
int _separator1 = 2, //DecimalSeparator
int _separator2 = 0) //ThousandSeparator
{
#DEFINE.AUTO('Auto')
// http://www.rgagnon.com/pbdetails/pb-0181.html
#DEFINE.LOCALE_USER_DEFAULT(1024)
#DEFINE.LOCALE_ICURRDIGITS(25)
#AOT
#PROPERTIES
#WinAPI // Used for regional settings
TreeNode treeNode;
int decimalPlaces;
;
treeNode = infolog.findNode(#ExtendedDataTypesPath + '\\' + _edt);
if (!treeNode)
return strfmt("%1", _number);
if (findproperty(treeNode.AOTgetProperties(),#PropertyNoOfDecimals) == #AUTO)
{
// get the number of decimals from the regional settings
decimalPlaces = str2int((WinAPI::getLocaleInfo(#LOCALE_USER_DEFAULT, #LOCALE_ICURRDIGITS)));
}
else
{
// get the number of decimals set by the developer in the property inspector
decimalPlaces = str2int(findproperty(treeNode.AOTgetProperties(),#PropertyNoOfDecimals));
}
return num2str(_number, _character, decimalPlaces, _separator1, _separator2);
}
usage example:
info(strfmt("%1", num2strEdt(20.34, 0, (identifierstr(myEDT)))));
Geen opmerkingen:
Een reactie posten