PDA

View Full Version : type casting float->int



slenkar
29-11-2010, 04:09 PM
is this the only way to cast from float to int?


result_flt:single=math.ArcTan2(dy,dx);
result_string2:string=floattostr(radtodeg(result_f lt));
result_int2:integer=strtoint(result_string2);
first:= result_int2+360;
result:= first Mod 360;

chronozphere
29-11-2010, 04:30 PM
lol, that's ridiculous! ;) You shouldn't do that by casting to string and back. Way too exprensive.

Just have a look at the Round(), Floor() and Ceil() functions in the math unit:

Some good info can be found here:
http://www.delphibasics.co.uk/RTL.asp?Name=Round

Btw: I don't understand your syntax. You're doing this:



result_flt:single=math.ArcTan2(dy,dx);


Is that even possible? Shouldn't it be?


var result_flt: single;
begin
result_flt := math.ArcTan2(dy,dx);
end;