February 4, 2010 at 12:16
filed under Dynamics AX
Tagged Data Types, Dynamics AX
Here’s a little ‘be-aware’ I’d like to share.
The function str2int() that converts a string to an integer will return ‘0’ if the input string is not an integer, so it is necessary to check if the string is an integer before casting it.
The function that does this is not IsNumeric() like in SQL or VB, but IsInteger().
Alternatively, you can also use str2IntOk(). Both are found in the global class.
I’ve seen people searching for this method (including me), so I just thought I’d share.
Here’s some sample code:
Update June 2016: if you input “123abd”, the str2int function will return 123, not 0 as you might expect from the “abc123” example!. So be sure to Always use the isInteger function before using str2int.
Andris
on September 22, 2011 at 15:10
Thanks :)