The AutoLisp Intermediate Tutorial
Conversion Functions:
fix float itoa atoi atof rtos angtos
fix - This function returns an integer. (NOTE: This function does not round numbers off!)
Syntax : (fix number)
number - any valid number.[integer or real number]
(fix 345) returns 345
(fix 345.9) returns 345
(fix -345) returns -345
(fix -345.9) returns -345
(fix "345JEFF") returns "Error: Bad Argument Type" ["345JEFF" is a string, not a number]
float - This function returns a real number.
Syntax : (float number)
number - any valid number.[integer or real number]
(float 345) returns 345.0
(float 345.9) returns 345.9
(float -345) returns -345.0
(float -345.9) returns -345.9
(float "345JEFF") returns "Error: Bad Argument Type" ["345JEFF" is a string, not a number]
itoa - This function changes an integer to a string.
Syntax : (itoa integer)
integer - any valid integer.
(itoa 345) returns "345"
(itoa 345.9) returns "Error: Bad Argument Type" [345.9 is a real number, not an integer]
(itoa -345) returns "-345"
(itoa -345.9) returns "Error: Bad Argument Type" [-345.9 is a real number, not an integer]
(itoa "345JEFF") returns "Error: Bad Argument Type" ["345JEFF" is a string, not an integer]
atoi - This function changes a string into an integer.
Syntax : (atoi string)
string - any valid string.
(atoi "345") returns 345
(atoi "345.9") returns 345
(atoi 345) returns "Error: Bad Argument Type" [345 is a number, not a string]
(atoi 345.9) returns "Error: Bad Argument Type" [345.9 is a number, not a string]
(atoi "-345") returns -345
(atoi "-345.9") returns -345
(atoi "345JEFF49") returns 345
(atoi "JEFF49") returns 0
Note: This function starts at the beginning of the string and continues until it finds a character that cannot be an integer.
atof - This function changes a string into a real number.
Syntax : (atof string)
string - any valid string.
(atof "345") returns 345.0
(atof "345.9") returns 345.9
(atof 345) returns "Error: Bad Argument Type" [345 is a number, not a string]
(atof 345.9) returns "Error: Bad Argument Type" [345.9 is a number, not a string]
(atof "-345") returns -345.0
(atof "-345.9") returns -345.9
(atof "345JEFF49") returns 345.0
(atof "JEFF49") returns 0.0
Note: This function starts at the beginning of the string and continues until it finds a character that cannot be a number.
rtos - This function converts numbers to a formatted string representing a distance.
Syntax : (rtos number mode precision)
number - Any valid number. [Real or Integer]
mode - This directly corresponds to LUnits system variable.
precision - This directly corresponds to the LUPrec system variable.
mode = 1 = Scientific
with precision = 1 (rtos 456.5 1 1) returns "4.6E+02"
with precision = 2 (rtos 456.5 1 2) returns "4.57E+02"
with precision = 3 (rtos 456.5 1 3) returns "4.565E+02"
with precision = 4 (rtos 456.5 1 4) returns "4.5650E+02"
with precision = 5 (rtos 456.5 1 5) returns "4.56500E+02"
with precision = 6 (rtos 456.5 1 6) returns "4.565000E+02"
with precision = 7 (rtos 456.5 1 7) returns "4.5650000E+02"
ect.....
mode = 2 = Engineering
with precision = 1 (rtos 456.5 2 1) returns "456.5"
with precision = 2 (rtos 456.5 2 2) returns "456.50"
with precision = 3 (rtos 456.5 2 3) returns "456.500"
with precision = 4 (rtos 456.5 2 4) returns "456.5000"
with precision = 5 (rtos 456.5 2 5) returns "456.50000"
with precision = 6 (rtos 456.5 2 6) returns "456.500000"
with precision = 7 (rtos 456.5 2 7) returns "456.5000000"
ect.....
mode = 3 = Decimal
with precision = 1 (rtos 456.5 3 1) returns "38'-0.5""
with precision = 2 (rtos 456.5 3 2) returns "38'-0.50""
with precision = 3 (rtos 456.5 3 3) returns "38'-0.500""
with precision = 4 (rtos 456.5 3 4) returns "38'-0.5000""
with precision = 5 (rtos 456.5 3 5) returns "38'-0.50000""
with precision = 6 (rtos 456.5 3 6) returns "38'-0.500000""
with precision = 7 (rtos 456.5 3 7) returns "38'-0.5000000"
ect.....
mode = 4 = Architectural
with precision = 1 (rtos 37.7071 4 1) returns "3'-1 1/2""
with precision = 2 (rtos 37.7071 4 2) returns "3'-1 3/4""
with precision = 3 (rtos 37.9 4 3) returns "3'-1 7/8""
with precision = 4 (rtos 37.7071 4 4) returns "3'-1 11/16""
with precision = 5 (rtos 37.7071 4 5) returns "3'-1 23/32""
with precision = 6 (rtos 37.7071 4 6) returns "3'-1 45/64""
with precision = 7 (rtos 37.7071 4 7) returns "3'-1 91/128""
ect.....
mode = 5 = Inch Fractional
with precision = 1 (rtos 37.7071 5 1) returns "371/2""
with precision = 2 (rtos 37.7071 5 2) returns "37 3/4""
with precision = 3 (rtos 37.9 5 3) returns "37 7/8""
with precision = 4 (rtos 37.7071 5 4) returns "37 11/16""
with precision = 5 (rtos 37.7071 5 5) returns "37 23/32""
with precision = 6 (rtos 37.7071 5 6) returns "37 45/64""
with precision = 7 (rtos 37.7071 5 7) returns "37 91/128""
ect.....
angtos - This function converts a number to a formatted string representing an angle.
Syntax : (angtos number mode precision)
number - Any valid number representing radians. [3.14159 radians = pi =180 degrees]
mode - This directly corresponds to AUnits system variable.
precision - This directly corresponds to the AUPrec system variable.
mode = 0 = Decimal Degrees
with precision = 1 (angtos 0.627102 0 1) returns "35.9"
with precision = 2 (angtos 0.627102 0 2) returns "35.93"
with precision = 3 (angtos 0.627102 0 3) returns "35.930"
with precision = 4 (angtos 0.627102 0 4) returns "35.9303"
with precision = 5 (angtos 0.627102 0 5) returns "35.93030"
ect.....
mode = 1 = Degrees Minutes Seconds
with precision = 1 (angtos 0.627102 1 1) returns " 35d56' "
with precision = 3 (angtos 0.627102 1 3) returns " 35d55'49" "
with precision = 5 (angtos 0.627102 1 4) returns " 35d55'49.1" "
with precision = 6 (angtos 0.627102 1 5) returns " 35d55'49.07" "
with precision = 7 (angtos 0.627102 1 6) returns " 35d55'49.073" "
ect.....
mode = 2 = Grads
with precision = 1 (angtos 0.627102 2 1) returns "39.9g"
with precision = 2 (angtos 0.627102 2 2) returns "39.92g"
with precision = 3 (angtos 0.627102 2 3) returns "39.923g"
with precision = 4 (angtos 0.627102 2 4) returns "39.9226g"
with precision = 5 (angtos 0.627102 2 5) returns "39.92255g"
ect.....
mode = 3 = Radians
with precision = 1 (angtos 0.627102 3 1) returns "0.6r"
with precision = 2 (angtos 0.627102 3 2) returns "0.63r"
with precision = 3 (angtos 0.627102 3 3) returns "0.627r"
with precision = 4 (angtos 0.627102 3 4) returns "0.6271r"
with precision = 5 (angtos 0.627102 3 5) returns "0.62710r"
ect.....
mode = 4 = Surveyor
with precision = 1 (angtos 0.627102 0 1) returns "N 54d4' E"
with precision = 2 (angtos 0.627102 0 2) returns "N 54d4' E"
with precision = 3 (angtos 0.627102 0 3) returns "N 54d4'11" E"
with precision = 4 (angtos 0.627102 0 4) returns "N 54d4'11" E"
with precision = 5 (angtos 0.627102 0 5) returns "N 54d4'10.9" E"
ect.....