Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

convert String to real?

9 REPLIES 9
Reply
Message 1 of 10
Anonymous
1810 Views, 9 Replies

convert String to real?

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"
9 REPLIES 9
Message 2 of 10
Anonymous
in reply to: Anonymous

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" > >
Message 3 of 10
Anonymous
in reply to: Anonymous

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
Message 4 of 10
Anonymous
in reply to: Anonymous

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
Message 5 of 10
Anonymous
in reply to: Anonymous

(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 > >
Message 6 of 10
Anonymous
in reply to: Anonymous

This is good one :) (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 > > > > > >
Message 7 of 10
Anonymous
in reply to: Anonymous

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 :) > > > (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 > > > > > > > > > > > >
Message 8 of 10
Anonymous
in reply to: Anonymous

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 :) > > > > > > (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 > > > > > > > > > > > > > > > > > > > >
Message 9 of 10
Anonymous
in reply to: Anonymous

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? > >
Message 10 of 10
Anonymous
in reply to: Anonymous

(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 :) > > > > > > > > > (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 > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost