
-----------------------------------
mat
Sun Apr 10, 2005 6:03 pm

variable type change
-----------------------------------
how do i change variable types?

ie real to an int


thanks

-----------------------------------
jamonathin
Sun Apr 10, 2005 6:09 pm


-----------------------------------
Easy. Use a round command.var r : real := 4.5678
var i : int := round (r)
put i
But if you just round r, it still cannot be used as an integer.
r := round (r)
for q : 1 .. r
end for

strint / intstr  = changing strings and integers
realstr / strreal  = changing string and reals.
There are also more options for realstr, but that one's basic.
Look up frealstr and erealstr in F10 help.

-----------------------------------
mat
Sun Apr 10, 2005 6:21 pm


-----------------------------------
i think i needed to give more detail...

How would i add a rounded real number to an int variable that already exists?

basicly, could i switch the real to an int (not rounding) so i could add it to other ints? 

is there a command for real to int like there is for string to int (strint)
?erealint, or something? that does not work.
thanks again,

-----------------------------------
jamonathin
Sun Apr 10, 2005 6:41 pm


-----------------------------------
You do a '+' sign?

Works.

var q : real := 5
var p : int := 1
put p + q

%or

var q : real := 5.4
var p : int := 1
put p + round (q)


Doesn't Work.
var q : real := 5.4
var p : int := 1
put p + q

As long as the real number is whole, it can be added to an integer.  There's no way to actually chane the real to an integer, but you can round the real number and make a new integer variable equal to that real number.

-----------------------------------
Drakain Zeil
Sun Apr 10, 2005 6:53 pm


-----------------------------------
intreal
realint
strint
intstr

and I think there's some others.

-----------------------------------
jamonathin
Sun Apr 10, 2005 7:34 pm


-----------------------------------
intreal
realint
strint
intstr

and I think there's some others.

intreal? realint? lol... it's called
real_var:=int_var
and
int_var:=round(real_var)

those don't exist, mainly because there's no point  :?
