Tbag Posted June 16, 2020 Posted June 16, 2020 (edited) I am trying to set a variable with distance between 2 points. I am getting 2 points from user input but when I try to convert to feet (2nd line of code) I am getting an error. I cannot figure out what is wrong with this: (setq distpcc (rtos(distance pt1 pt2) 2 8)) (setq distpcc2 (/ distpcc 12 )) Thanks Edited June 16, 2020 by Tbag Quote
jonathann3891 Posted June 16, 2020 Posted June 16, 2020 If you could post your whole code, that would be helpful. Something like this maybe? (defun c:ttt (/ P1 P2 Z1 Z2) (setq Pt1 (getpoint "\nSelect First Point")) (setq Pt2 (getpoint "\nSelect Second Point")) (setq Z1 (nth 2 Pt1)) (setq Z2 (nth 2 Pt2)) (setq VAL (rtos (- Z1 Z2))) ) Quote
Tbag Posted June 16, 2020 Author Posted June 16, 2020 I would like to divide distpcc variable in (setq distpcc (rtos(distance pt1 pt2) 2 8)) by 12 so I added (setq distpcc2 (/ distpcc 12 )) but It does not work. Is it because distpcc is a string and it is not a real number? Thanks,. Quote
Hippe013 Posted June 16, 2020 Posted June 16, 2020 (edited) ;Original Code: (setq distpcc (rtos(distance pt1 pt2) 2 8)) (setq distpcc2 (/ distpcc 12 )) ;Just dont convert it to a string, do the following. (setq distpcc2 (/ (distance pt1 pt2) 12.0)) ;Also you should use decimal when dividing ;Test the following (rtos (/ 1 12) 2 8) ;versus (rtos (/ 1.0 12.0) 2 8) Edited June 16, 2020 by Hippe013 Quote
pBe Posted June 17, 2020 Posted June 17, 2020 10 hours ago, Tbag said: Is it because distpcc is a string and it is not a real number? Simply put, you cannot perform an arithmetic function on a string stype value. Unless of course you are working on some other programming language where the symbol "+" also means concatenate. Quote
Tbag Posted June 18, 2020 Author Posted June 18, 2020 On 6/16/2020 at 3:26 PM, Hippe013 said: ;Original Code: (setq distpcc (rtos(distance pt1 pt2) 2 8)) (setq distpcc2 (/ distpcc 12 )) ;Just dont convert it to a string, do the following. (setq distpcc2 (/ (distance pt1 pt2) 12.0)) ;Also you should use decimal when dividing ;Test the following (rtos (/ 1 12) 2 8) ;versus (rtos (/ 1.0 12.0) 2 8) Thanks so much, very helpful. Quote
Tbag Posted June 18, 2020 Author Posted June 18, 2020 On 6/17/2020 at 1:07 AM, pBe said: Simply put, you cannot perform an arithmetic function on a string stype value. Unless of course you are working on some other programming language where the symbol "+" also means concatenate. Thanks. makes sense. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.