Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
*Virgis
Message 1 of 10 (525 Views)

convert String to real?

525 Views, 9 Replies
08-03-2004 06:18 AM
Hi, What Vlisp command would convert String to real? (defun c:AOF () (SETQ GL (ENTGET (ENTLAST))) (SETQ GT (CDR (ASSOC 1 A))) (setq GA (* 0.0001 GT)) (print GA) (print) ) error: bad argument type: consp "1998289.8296"
*Alan Henderson
Message 2 of 10 (525 Views)

Re: convert String to real?

08-03-2004 06:23 AM in reply to: *Virgis
ATOF "Virgis" wrote in message news:410f8fae$1_3@newsprd01... > Hi, > What Vlisp command would convert String to real? > > > > (defun c:AOF () > (SETQ GL (ENTGET (ENTLAST))) > (SETQ GT (CDR (ASSOC 1 A))) > (setq GA (* 0.0001 GT)) > (print GA) > (print) > ) > > error: bad argument type: consp "1998289.8296" > >
*Jürg Menzi
Message 3 of 10 (525 Views)

Re: convert String to real?

08-03-2004 07:24 AM in reply to: *Virgis
Hi Virgis 'atof' like Alan says. To prevent unexpected errors, I would propose this function: (defun MeAtof (Val) (if (not (wcmatch Val "*[~0-9.-]*")) (atof Val)) ) I've seen, that you plan to read a text string. Probably this string can contain characters also. In this case 'atof' returns 0, 'MeAtof' returns nil. Following this, your function may work like this: ... (if (setq RetVal (MeAtof GT)) (setq GA (* 0.0001 RetVal)) (setq GA "Text is not nummeric.") ) (print GA) Cheers -- Juerg Menzi MENZI ENGINEERING GmbH, Switzerland http://www.menziengineering.ch
*Virgis
Message 4 of 10 (525 Views)

Re: convert String to real?

08-03-2004 08:21 AM in reply to: *Virgis
Thanks it works! (defun c:AOF () (SETQ A (ENTGET (ENTLAST))) (SETQ AA (CDR (ASSOC 1 A))) (SETQ B (ATOF AA)) (setq BB (* 0.0001 B)) (COMMAND "TEXT" PAUSE "" BB) ) But is still one problem I become such result 187.7116600000000 I need this one: 187.71 Virgis
*Jim Claypool
Message 5 of 10 (525 Views)

Re: convert String to real?

08-03-2004 09:13 AM in reply to: *Virgis
(COMMAND "TEXT" PAUSE "" (rtos BB 2 2)) "Virgis" wrote in message news:410fad69_3@newsprd01... > Thanks it works! > > (defun c:AOF () > (SETQ A (ENTGET (ENTLAST))) > (SETQ AA (CDR (ASSOC 1 A))) > (SETQ B (ATOF AA)) > (setq BB (* 0.0001 B)) > (COMMAND "TEXT" PAUSE "" BB) > ) > > But is still one problem > I become such result > > 187.7116600000000 > > I need this one: > > 187.71 > > Virgis > >
*Virgis
Message 6 of 10 (525 Views)

Re: convert String to real?

08-03-2004 09:43 AM in reply to: *Virgis
This is good one :smileyhappy: (defun c:TU () (SETQ SS (CAR (ENTSEL))) (SETQ A (ENTGET SS)) (SETQ AA (CDR (ASSOC 1 A))) (SETQ B (ATOF AA)) (setq BB (* 0.0001 B)) (setq C (RTOS BB 2 2)) (SETQ CC (vl-string-right-trim "0" C)) (COMMAND "TEXT" "J" "BR" PAUSE "0" CC) ) "Jim Claypool" wrote in message news:410fb9be_3@newsprd01... > (COMMAND "TEXT" PAUSE "" (rtos BB 2 2)) > > "Virgis" wrote in message news:410fad69_3@newsprd01... > > Thanks it works! > > > > (defun c:AOF () > > (SETQ A (ENTGET (ENTLAST))) > > (SETQ AA (CDR (ASSOC 1 A))) > > (SETQ B (ATOF AA)) > > (setq BB (* 0.0001 B)) > > (COMMAND "TEXT" PAUSE "" BB) > > ) > > > > But is still one problem > > I become such result > > > > 187.7116600000000 > > > > I need this one: > > > > 187.71 > > > > Virgis > > > > > >
*Jim Claypool
Message 7 of 10 (525 Views)

Re: convert String to real?

08-03-2004 11:41 AM in reply to: *Virgis
If you trim the trailing 0's and your value is 187.00 you will have "187." Is this really what you want? You might want to trim the decimal point too. (SETQ CC (vl-string-trim "." (vl-string-right-trim "0" C))) "Virgis" wrote in message news:410fc03b_2@newsprd01... > This is good one :smileyhappy: > > > (defun c:TU () > (SETQ SS (CAR (ENTSEL))) > (SETQ A (ENTGET SS)) > (SETQ AA (CDR (ASSOC 1 A))) > (SETQ B (ATOF AA)) > (setq BB (* 0.0001 B)) > (setq C (RTOS BB 2 2)) > (SETQ CC (vl-string-right-trim "0" C)) > (COMMAND "TEXT" "J" "BR" PAUSE "0" CC) > ) > > > > > "Jim Claypool" wrote in message > news:410fb9be_3@newsprd01... > > (COMMAND "TEXT" PAUSE "" (rtos BB 2 2)) > > > > "Virgis" wrote in message news:410fad69_3@newsprd01... > > > Thanks it works! > > > > > > (defun c:AOF () > > > (SETQ A (ENTGET (ENTLAST))) > > > (SETQ AA (CDR (ASSOC 1 A))) > > > (SETQ B (ATOF AA)) > > > (setq BB (* 0.0001 B)) > > > (COMMAND "TEXT" PAUSE "" BB) > > > ) > > > > > > But is still one problem > > > I become such result > > > > > > 187.7116600000000 > > > > > > I need this one: > > > > > > 187.71 > > > > > > Virgis > > > > > > > > > > > >
*Virgis
Message 8 of 10 (525 Views)

Re: convert String to real?

08-03-2004 11:57 PM in reply to: *Virgis
Actually I want to have the result 187.00 and now I have 187 Maybe You know how? ----- Original Message ----- From: "Jim Claypool" Newsgroups: autodesk.autocad.customization Sent: Tuesday, August 03, 2004 8:41 PM Subject: Re: convert String to real? > If you trim the trailing 0's and your value is 187.00 you will have "187." > Is this really what you want? You might want to trim the decimal point too. > > (SETQ CC (vl-string-trim "." (vl-string-right-trim "0" C))) > > > "Virgis" wrote in message news:410fc03b_2@newsprd01... > > This is good one :smileyhappy: > > > > > > (defun c:TU () > > (SETQ SS (CAR (ENTSEL))) > > (SETQ A (ENTGET SS)) > > (SETQ AA (CDR (ASSOC 1 A))) > > (SETQ B (ATOF AA)) > > (setq BB (* 0.0001 B)) > > (setq C (RTOS BB 2 2)) > > (SETQ CC (vl-string-right-trim "0" C)) > > (COMMAND "TEXT" "J" "BR" PAUSE "0" CC) > > ) > > > > > > > > > > "Jim Claypool" wrote in message > > news:410fb9be_3@newsprd01... > > > (COMMAND "TEXT" PAUSE "" (rtos BB 2 2)) > > > > > > "Virgis" wrote in message news:410fad69_3@newsprd01... > > > > Thanks it works! > > > > > > > > (defun c:AOF () > > > > (SETQ A (ENTGET (ENTLAST))) > > > > (SETQ AA (CDR (ASSOC 1 A))) > > > > (SETQ B (ATOF AA)) > > > > (setq BB (* 0.0001 B)) > > > > (COMMAND "TEXT" PAUSE "" BB) > > > > ) > > > > > > > > But is still one problem > > > > I become such result > > > > > > > > 187.7116600000000 > > > > > > > > I need this one: > > > > > > > > 187.71 > > > > > > > > Virgis > > > > > > > > > > > > > > > > > > > >
*MP
Message 9 of 10 (525 Views)

Re: convert String to real?

08-04-2004 07:09 AM in reply to: *Virgis
Command: (rtos (atof "187") 2 2) "187.00" "Virgis" wrote in message news:411087e8_3@newsprd01... > Actually I want to have the result 187.00 > and now I have 187 > Maybe You know how? > >
*Jim Claypool
Message 10 of 10 (525 Views)

Re: convert String to real?

08-05-2004 06:50 AM in reply to: *Virgis
(defun c:TU () (SETQ SS (CAR (ENTSEL))) (SETQ A (ENTGET SS)) (SETQ AA (CDR (ASSOC 1 A))) (SETQ B (ATOF AA)) (setq BB (* 0.0001 B)) (setq C (RTOS BB 2 2)) ;; (SETQ CC (vl-string-right-trim "0" C)) ;; REMOVE THIS LINE (COMMAND "TEXT" "J" "BR" PAUSE "0" C) ;; CHANGE CC to C ) "Virgis" wrote in message news:411087e8_3@newsprd01... > Actually I want to have the result 187.00 > and now I have 187 > Maybe You know how? > > > > > ----- Original Message ----- > From: "Jim Claypool" > Newsgroups: autodesk.autocad.customization > Sent: Tuesday, August 03, 2004 8:41 PM > Subject: Re: convert String to real? > > > > If you trim the trailing 0's and your value is 187.00 you will have "187." > > Is this really what you want? You might want to trim the decimal point > too. > > > > (SETQ CC (vl-string-trim "." (vl-string-right-trim "0" C))) > > > > > > "Virgis" wrote in message news:410fc03b_2@newsprd01... > > > This is good one :smileyhappy: > > > > > > > > > (defun c:TU () > > > (SETQ SS (CAR (ENTSEL))) > > > (SETQ A (ENTGET SS)) > > > (SETQ AA (CDR (ASSOC 1 A))) > > > (SETQ B (ATOF AA)) > > > (setq BB (* 0.0001 B)) > > > (setq C (RTOS BB 2 2)) > > > (SETQ CC (vl-string-right-trim "0" C)) > > > (COMMAND "TEXT" "J" "BR" PAUSE "0" CC) > > > ) > > > > > > > > > > > > > > > "Jim Claypool" wrote in message > > > news:410fb9be_3@newsprd01... > > > > (COMMAND "TEXT" PAUSE "" (rtos BB 2 2)) > > > > > > > > "Virgis" wrote in message news:410fad69_3@newsprd01... > > > > > Thanks it works! > > > > > > > > > > (defun c:AOF () > > > > > (SETQ A (ENTGET (ENTLAST))) > > > > > (SETQ AA (CDR (ASSOC 1 A))) > > > > > (SETQ B (ATOF AA)) > > > > > (setq BB (* 0.0001 B)) > > > > > (COMMAND "TEXT" PAUSE "" BB) > > > > > ) > > > > > > > > > > But is still one problem > > > > > I become such result > > > > > > > > > > 187.7116600000000 > > > > > > > > > > I need this one: > > > > > > > > > > 187.71 > > > > > > > > > > Virgis > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!