The AutoCADET's Guide to Visual LISP: Optimize and Customize Your AutoCAD Design Environment

In programming, the primary data elements you work with are numbers and strings (sequences of characters). In AutoCAD, you work with dimensions, which are strings containing numbers representing parameter data, and applications often must report the results of computations in string format to users, files, and drawings.
This chapter explores the Visual LISP subrs for converting between strings and numbers. Integer and real numbers are covered as well as two uses of real numbers, scalars and angles. In addition, radians and how you use them in Visual LISP are also described in this chapter.
Two simple subrs convert data between integer format and string format. The ATOI (ASCII TO Integer) subr takes a string containing digits and returns the value they represent as an integer. For example, (ATOI "100") returns the integer 100.
If ATOI is presented with a string that contains both characters and numbers, it converts as many numbers as it can until it encounters a non-numeric character. For example, the expression (ATOI "12AB34") returns the integer value 12.
When presented with something it cannot translate to an integer, ATOI returns a value of 0. For example, (ATOI "AB12") returns 0 because the first characters are non-numeric and cannot be converted. Therefore, it is important to remove any formatting characters or other non-numeric characters from the string before trying to convert it to an integer.
The opposite of ATOI is ITOA (Integer TO ASCII).