Jump to content

Recommended Posts

Posted

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?

Posted

Lee Mac,

 

You may also want to look into the DIMZIN sysvar as it controls the format of the return for ( rtos ) calls. -David

Posted

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

Posted

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

Posted

Thanks David, very informative.

 

I wonder why they chose 32,767 as the limit on integers.... seems quite random...

Posted

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

  • 3 years later...
Posted

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

Posted

Use type function .

 

Examples ....

 

(setq a 123)
(setq b "Point-123")

(type a) ;; INT 
(type b) ;; STR 

Posted
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))

Posted

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

Posted

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

Posted
Wow, this is an old thread.

 

 

Yeah, I'll say! LeeMac wasn't yet familiar with RTOS :lol:

Posted
(setq answer (getstring "\nEnter Value: "))
(setq answer 
(if (numberp (setq a (eval (read answer )))) a answer))

 

 

Try an architectural distance:

 

ie 1'-2"

Posted
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. :thumbsup:

Posted

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

Posted
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 :shock:

Posted
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 :shock:

 

Oh yeah... :o , 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.

Posted
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? :beer:

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...