Convert a real number to a string in AX Fetch Decimal part and fetch only number without decimal in x++ d365


Converts a real number to a string. Fetch Decimal part and fetch only number without decimal in x++ d365
str num2Str(
    real number,
    int character,
    int decimals,
    int separator1,
    int separator2)

Parameters :

number :The real number to convert to a string.

character:The minimum number of characters required in the text.
decimals: The required number of decimal places.
separator1 : DecimalSeparator enumeration value.
separator2:ThousandSeparator enumeration value.
Possible enumeration values for the separator1 parameter are:
  • 1 – point (.)
  • 2 – comma (,)
Possible values for the separator2 parameter are:
  • 0 – no thousands separator
  • 1 – point (.)
  • 2 – comma (,)
  • 3 – space ( )
static void Job_Num2Str(Args _args) { real realNum = 0.1294567890123456777; // 19 decimals places. ; info(Num2Str(realNum,0,16,1,3)); // 16 decimal places info(Num2Str(realNum,0,17,1,3)); // 17 decimal places }
str strqtyWork =num2Str(whsLoadListTmp.QtyWork,0,2,0,0); str strSalesPrice =num2Str(whsLoadListTmp.SalesPrice,0,2,0,0);
xmlText =xmlDoc.createTextNode(num2Str(custInvoiceJour.InvoiceAmount,0,2,1,0));

Output

The messages are in the following Infolog output. The first number in the display contains 16 decimal place digits, whereas the second contains only 2.

Message (10:18:12)

0.1294567890123457

0.13


  str strqtyWork =num2Str(whsLoadListTmp.QtyWork,0,0,0,0);

        str strSalesPrice =num2Str(whsLoadListTmp.SalesPrice,0,0,0,0);


above rounds the values
3,326.72 to 3327


https://docs.microsoft.com/en-us/previous-versions/dynamics/ax-2012/reference/aa866120(v=ax.60)?redirectedfrom=MSDN
 Fetch Decimal part and fetch only number without decimal in x++ d365
//FETCH BEFORE DECIMAL str strqtyWorkBeforeDecimal =int2Str(whsLoadListTmp.QtyWork); str strSalesPriceBeforeDecimal =int2Str(whsLoadListTmp.SalesPrice); //FETCH BEFORE DECIMAL str strqtyWork =num2Str(whsLoadListTmp.QtyWork,0,2,1,0); str strSalesPrice =num2Str(whsLoadListTmp.SalesPrice,0,2,1,0); //FETCH AFTER DECIMAL AND COMBINE strqtyWork =strqtyWorkBeforeDecimal + subStr(strqtyWork,strScan(strqtyWork,".",1,strLen(strqtyWork))+1,2); strSalesPrice =strSalesPriceBeforeDecimal+ subStr(strSalesPrice,strScan(strSalesPrice,".",1,strLen(strSalesPrice))+1,2); //FETCH AFTER DECIMAL AND COMBINE

Comments