Author Topic: Real to Integer  (Read 4181 times)

0 Members and 1 Guest are viewing this topic.

MeasureUp

  • Bull Frog
  • Posts: 465
Real to Integer
« on: July 12, 2010, 07:41:18 PM »
I am confused when trying to convert real to integer.
Could you please let me know if the following is correct.
Thanks in advance.

Code: [Select]
(setq Num (getreal "\nEnter the Level Number: " ))
(command "text" pt1 "" "" (rtos Num 2 0) "")

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Real to Integer
« Reply #1 on: July 12, 2010, 07:44:46 PM »

Start here:
What does RTOS do ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MeasureUp

  • Bull Frog
  • Posts: 465
Re: Real to Integer
« Reply #2 on: July 12, 2010, 07:54:13 PM »
Converts a number into a string.
- from the help.
The reason I rose the question is I don't know which function is to convert a real into an integer or simply the getreal is not correctly applied.
« Last Edit: July 12, 2010, 08:06:27 PM by MeasureUp »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Real to Integer
« Reply #3 on: July 12, 2010, 07:55:49 PM »


What is the result of this ?

(setq Num (getreal "\nEnter the Level Number: " ))


(setq intNo (rtos Num 2 0))
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Real to Integer
« Reply #4 on: July 12, 2010, 08:08:35 PM »

Rather than change your previous response, just answer my question.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MeasureUp

  • Bull Frog
  • Posts: 465
Re: Real to Integer
« Reply #5 on: July 12, 2010, 08:10:58 PM »
Sorry, there is not correct with "convert a real into a string" in my last reply.
It should be "convert a real into an integer".

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Real to Integer
« Reply #6 on: July 12, 2010, 08:12:04 PM »

I know what you meant.

BUT .. what is the answer to my question ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MeasureUp

  • Bull Frog
  • Posts: 465
Re: Real to Integer
« Reply #7 on: July 12, 2010, 08:14:51 PM »
Obviously, as the result, your "intNo" is a string.
But I want the input to be an integer.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Real to Integer
« Reply #8 on: July 12, 2010, 08:16:01 PM »
Just wait !!

What happens when you try your example?

Then, what happens when you try these ?

(setq pt1 (getpoint "\n Select Point"))
(command "text" pt1 "" "" "42" "")

(setq pt2 (getpoint "\n Select Point"))
(command "text" pt2 "" "" 42 "")


(setq pt3 (getpoint "\n Select Point"))
(command "text" pt3 "" "" "42" )

(setq pt4 (getpoint "\n Select Point"))
(command "text" pt4 "" "" 42 )

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MeasureUp

  • Bull Frog
  • Posts: 465
Re: Real to Integer
« Reply #9 on: July 12, 2010, 08:25:17 PM »
Just wait !!

What happens when you try your example?

Then, what happens when you try these ?

(setq pt1 (getpoint "\n Select Point"))
(command "text" pt1 "" "" "42" "")

(setq pt2 (getpoint "\n Select Point"))
(command "text" pt2 "" "" 42 "")


(setq pt3 (getpoint "\n Select Point"))
(command "text" pt3 "" "" "42" )

(setq pt4 (getpoint "\n Select Point"))
(command "text" pt4 "" "" 42 )


That was my typo shown in red above.
I think the "42" is an integer in the pt3 sample while the 42 in a string in the pt4 sample.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Real to Integer
« Reply #10 on: July 12, 2010, 08:27:46 PM »
Just wait !!

What happens when you try your example?

Then, what happens when you try these ?

(setq pt1 (getpoint "\n Select Point"))
(command "text" pt1 "" "" "42" "")

(setq pt2 (getpoint "\n Select Point"))
(command "text" pt2 "" "" 42 "")


(setq pt3 (getpoint "\n Select Point"))
(command "text" pt3 "" "" "42" )

(setq pt4 (getpoint "\n Select Point"))
(command "text" pt4 "" "" 42 )


That was my typo shown in red above.
I think the "42" is an integer in the pt3 sample while the 42 in a string in the pt4 sample.

Correct. Either 42 or "42" work.
The issue was not with the conversion, it was with the command.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Real to Integer
« Reply #11 on: July 12, 2010, 08:29:36 PM »
NOW ..

What does this do for you ??

(setq realNum (getreal "\nEnter the Level Number: " ))
(setq intNo (atoi (rtos realNum 2 0)))


and

(setq pt1 (getpoint "\n Select Point"))
(setq LevelNum (getint "\nEnter the Level Number: " ))
(vl-cmdf "text" pt1 "" "" LevelNum)
« Last Edit: July 12, 2010, 08:34:06 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MeasureUp

  • Bull Frog
  • Posts: 465
Re: Real to Integer
« Reply #12 on: July 12, 2010, 08:42:37 PM »
So what you mean is using the "getint" will give the correct answer instead of using the "getreal".

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Real to Integer
« Reply #13 on: July 12, 2010, 08:46:28 PM »
So what you mean is using the "getint" will give the correct answer instead of using the "getreal".

If the question is "I want an Integer", then using getint()  is the normal answer.

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MeasureUp

  • Bull Frog
  • Posts: 465
Re: Real to Integer
« Reply #14 on: July 12, 2010, 08:50:04 PM »
Yes, this is what I want to know. Thanks.