Lee Mac Posted September 20, 2008 Posted September 20, 2008 This may be a silly question, but I cant seem to find the right LISP function. I need to convert a real to a string. I have found: atoi "string to integer" itoa "integer to string" atof "string to real" but no "real to string" Any ideas? Quote
David Bethel Posted September 20, 2008 Posted September 20, 2008 Lee Mac, You may also want to look into the DIMZIN sysvar as it controls the format of the return for ( rtos ) calls. -David Quote
Lee Mac Posted September 20, 2008 Author Posted September 20, 2008 Thanks for the help guys. - So something like this to set real to a string with 2 decimal places... (defun test (/ olddim a1) (setq olddim (getvar "dimzin)) (setvar "dimzin" 0) (setq a1 (rtos 123.32 2 2)) (alert a1) (setvar "dimzin" olddim) ) Quote
David Bethel Posted September 20, 2008 Posted September 20, 2008 Correct. A couple of things to watch out for with number to sting conversions: (sslength) is documented as returning an integer. It returns a real when the PICKSET is larger than 32767 entities. (itoa (sslength ss)) can fail in that scenario (rtos (sslength ss) 2 0) will always work (angtos) doesn't conform to to the units value. You must decrease it by 1. ie (angtos 0.785398 0 2) returns "45.00" Don't ask me why. DIMZIN bit flag 8 did not use to be documented very well. Under VLisp help DIMZIN -> String Conversions is actually a good reference At least the A2K version. -David Quote
Lee Mac Posted September 20, 2008 Author Posted September 20, 2008 Thanks David, very informative. I wonder why they chose 32,767 as the limit on integers.... seems quite random... Quote
David Bethel Posted September 20, 2008 Posted September 20, 2008 Lee Mac, 2 to 16th power is 65536. Take into account positive and negative, basically half of the number less a place for 0 and you get 32767. At least that's how I remember it. -David Quote
bijoyvm Posted May 24, 2012 Posted May 24, 2012 Need Help to create a code.. (setq a 123) ; if I add number (setq a “point-123”) ;sometimes my input value should be like this Please , I need help to use IF or COND function in lisp For eg. If I enter 123, It should prompt like --- it is real And if I enter “point-123” It should prompt --- It is String thanks & regards Bijoy Quote
Tharwat Posted May 24, 2012 Posted May 24, 2012 Use type function . Examples .... (setq a 123) (setq b "Point-123") (type a) ;; INT (type b) ;; STR Quote
pBe Posted May 24, 2012 Posted May 24, 2012 Need Help to create a code.. (setq a 123) ; if I add number (setq a “point-123”) ;sometimes my input value should be like this Please , I need help to use IF or COND function in lisp For eg. If I enter 123, It should prompt like --- it is real And if I enter “point-123” It should prompt --- It is String thanks & regards Bijoy (setq answer (getstring "\nEnter Value: ")) (setq answer (if (numberp (setq a (eval (read answer )))) a answer)) Quote
David Bethel Posted May 24, 2012 Posted May 24, 2012 Wow, this is an old thread. Your request can be a quite involved process due to LUNITS. I would be inclined to use multiple call to (distof) But I'm pretty sure you could figure out some way to fool it into giving a false return. -David Quote
pBe Posted May 24, 2012 Posted May 24, 2012 What i posted before involves conversion to correspond with the input: now if you only need to "see" waht the user type (prin1 (if (numberp (eval (read answer ))) "It's a number" "It's a String")) On another note, you said REAL (setq answer (if (numberp (setq a (eval (read answer )))) [b](float[/b] a[b])[/b] answer)) Quote
LibertyOne Posted May 24, 2012 Posted May 24, 2012 Wow, this is an old thread. Yeah, I'll say! LeeMac wasn't yet familiar with RTOS Quote
David Bethel Posted May 24, 2012 Posted May 24, 2012 (setq answer (getstring "\nEnter Value: ")) (setq answer (if (numberp (setq a (eval (read answer )))) a answer)) Try an architectural distance: ie 1'-2" Quote
pBe Posted May 24, 2012 Posted May 24, 2012 Try an architectural distance: ie 1'-2" You got a point there David, with an input like that, the line wont be as generic as what my original intent was. I have a feeling that the OP would want to use the input either for a value to write on an attribute/text or use the value for an arithmetic function. Guess it all boils down to what the OP's planning to do with the value. Good catch David. Quote
BIGAL Posted May 25, 2012 Posted May 25, 2012 Just a bit of obscure maybe on the same theme ; if less than 10 (if (< (car dwgnum) 10.0) (setq newstr2 (strcat dwgname "-D0" (rtos sheetnum 2 0))) (setq newstr2 (strcat dwgname "-D" (rtos sheetnum 2 0))) ) Quote
eldon Posted May 25, 2012 Posted May 25, 2012 I have a feeling that the OP would want to use the input either for a value to write on an attribute/text or use the value for an arithmetic function.Guess it all boils down to what the OP's planning to do with the value. It should be pointed out here that the OP that you are referring to is a hijacker of the original thread, and bijoyvm should have started a new thread. Perhaps a moderator can sort out the mess Quote
pBe Posted May 25, 2012 Posted May 25, 2012 It should be pointed out here that the OP that you are referring to is a hijacker of the original thread, and bijoyvm should have started a new thread. Perhaps a moderator can sort out the mess Oh yeah... , what am i thinking!! Brilliant deduction eldon. The OP would mean Lee Mac then.. (where is that fine lad anyway?..) guess we'll call bijoyvm "Other Poster" [that can also mean us??!!? darn...] Careless of me... Good catch though. Quote
Dadgad Posted May 25, 2012 Posted May 25, 2012 Wow, this is an old thread. -David Yeah, some newbie by the name of Lee Mac, sort of rings a bell though doesn't it? 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.