rtos (real to string) and angtos (angle to string) convert numeric values used in AutoCAD to string values that can be used in output or as textual data. The rtos function converts a real value, and angtos converts an angle. The format of the result string is controlled by the value of AutoCAD system variables: the units and precision are specified by LUNITS and LUPREC for real (linear) values and by AUNITS and AUPREC for angular values. For both functions, the dimensioning variable DIMZIN controls how leading and trailing zeros are written to the result string.
The functionsrtos and the values returned (assuming the DIMZIN system variable equals 0). Precision (the third argument to rtos) is set to 4 places in the first call and 2 places in the others.
The following code fragments show calls to(setq x 17.5)
(setq str "\nValue formatted as ")
(setq fmtval (rtos x 1 4)) ; Mode 1 = scientific
(princ (strcat str fmtval)) ; displays  Value formatted as 1.7500E+01
(setq fmtval (rtos x 2 2)) ; Mode 2 = decimal
(princ (strcat str fmtval)) ; displays  Value formatted as 17.50
(setq fmtval (rtos x 3 2)) ; Mode 3 = engineering
(princ (strcat str fmtval)) ; displays  Value formatted as 1'-5.50"
(setq fmtval (rtos x 4 2)) ; Mode 4 = architectural
(princ (strcat str fmtval)) ; displays  Value formatted as 1'-5 1/2"
(setq fmtval (rtos x 5 2)) ; Mode 5 = fractional
(princ (strcat str fmtval)) ; displays  Value formatted as 17 1/2
rtos differs for engineering (mode equals 3), architectural (mode equals 4), and fractional (mode equals 5) units. For example, the first two lines of the preceding sample output would be the same, but the last three lines would appear as follows:
When the UNOTHODE system variable is set to 1, specifying that units are displayed as entered, the string returned byValue formatted as 1'5.50"
Value formatted as 1'5-1/2"
Value formatted as 17-1/2''
angtos function takes the ANGBASE system variable into account, the following code always returns "0":
Because the(angtos (getvar "angbase"))
There is no AutoLISP function that returns a string version (in the current mode/precision) of either the amount of rotation of ANGBASE from true zero (East) or an arbitrary angle in radians.
To find the amount of rotation of ANGBASE from AutoCAD zero (East) or the size of an arbitrary angle, you can do one of the following:
(atof (angtos 0)) from 360 degrees (2pi; radians or 400 grads) also yields the rotation of ANGBASE from 0.
Subtracting the result ofdistof (distance to floating point) function is the complement of rtos. Therefore, the following calls, which use the strings generated in the previous examples, all return the same value: 17.5. (Note the use of the backslash (\) with modes 3 and 4.)
The(distof "1.7500E+01" 1) ; Mode 1 = scientific
(distof "17.50" 2) ; Mode 2 = decimal
(distof "1'-5.50\"" 3) ; Mode 3 = engineering
(distof "1'-5 1/2\"" 4) ; Mode 4 = architectural
(distof "17 1/2" 5) ; Mode 5 = fractional
angtos and the values returned (still assuming that DIMZIN equals 0). Precision (the third argument to angtos) is set to 0 places in the first call, 4 places in the next three calls, and 2 places in the last.
The following code fragments show similar calls to(setq ang 3.14159 str2 "\nAngle formatted as ")
(setq fmtval (angtos ang 0 0)) ; Mode 0 = degrees
(princ (strcat str2 fmtval)) ; displays Angle formatted as 180
(setq fmtval (angtos ang 1 4)) ; Mode 1 = deg/min/sec
(princ (strcat str2 fmtval)) ; displays Angle formatted as 180d0'0"
(setq fmtval (angtos ang 2 4)) ; Mode 2 = grads
(princ (strcat str2 fmtval)) ; displays Angle formatted as 200.0000g
(setq fmtval (angtos ang 3 4)) ; Mode 3 = radians
(princ (strcat str2 fmtval)) ; displays Angle formatted as 3.1416r
(setq fmtval (angtos ang 4 2)) ; Mode 4 = surveyor's
(princ (strcat str2 fmtval)) ; displays Angle formatted as W
angtos when it returns a string in surveyor's units (mode equals 4). If UNITMODE equals 0, the string returned can include spaces (for example, "N 45d E"); if UNITMODE equals 1, the string contains no spaces (for example, "N45dE").
The UNITHODE system variable also affects strings returned byangtof function complements angtos, so all of the following calls return the same value: 3.14159.
The(angtof "180" 0) ; Mode 0 = degrees
(angtof "180d0'0\"" 1) ; Mode 1 = deg/min/sec
(angtof "200.0000g" 2) ; Mode 2 = grads
(angtof "3.14159r" 3) ; Mode 3 = radians
(angtof "W" 4) ; Mode 4 = surveyor's
angtof and distof demonstrate this action.
When you have a string specifying a distance in feet and inches, or an angle in degrees, minutes, and seconds, you must precede the quotation mark with a backslash (\") so it doesn't look like the end of the string. The preceding examples of