str2Num Function
Applies To: Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012
Converts a string to a real number.
real str2Num(str _text)
Parameters
Parameter |
Description |
---|---|
_text |
The string to convert to a real number. |
Return Value
The real number if the specified string contains a valid number; otherwise, zero.
Remarks
The following are examples of the usage of this function:
str2Num("123.45") returns the value 123.45.
str2Num("a123") returns the value 0.0.
str2Num("123a") returns the value 123.00.
Scanning occurs from left to right and terminates when a character cannot be converted to part of a real number.
Example
static void str2NumToReal(Args _arg)
{
real r;
str s;
;
r = str2Num("3.15");
s = strFmt("r = %1", r);
info(s);
}
/*** Infolog output.
Message_@SYS14327 (02:36:12 pm)
r = 3.15
***/
static void str2NumExponentialSyntax(Args _args)
{
Qty qty1, qty2, qty3;
;
qty1 = str2num('1e-3'); // Bad syntax by the user.
qty2 = str2num('1.e-3');
qty3 = str2num('1.0e-3');
info(strfmt('Result: %1; Expected: %2', num2str(qty1, 0,3,2,0), '0.001'));
info(strfmt('Result: %1; Expected: %2', num2str(qty2, 0,3,2,0), '0.001'));
info(strfmt('Result: %1; Expected: %2', num2str(qty3, 0,3,2,0), '0.001'));
}
/*** Infolog output. The first result differs from expectations.
Message_@SYS14327 (02:20:55 pm)
Result: 1,000; Expected: 0.001
Result: 0,001; Expected: 0.001
Result: 0,001; Expected: 0.001
***/
See also
Announcements: To see known issues and recent fixes, use Issue search in Microsoft Dynamics Lifecycle Services (LCS).