Results 1 to 2 of 2

Thread: type casting float->int

  1. #1

    type casting float->int

    is this the only way to cast from float to int?
    Code:
    result_flt:single=math.ArcTan2(dy,dx);
             result_string2:string=floattostr(radtodeg(result_flt));
             result_int2:integer=strtoint(result_string2);
             first:= result_int2+360;
             result:= first Mod 360;

  2. #2
    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:

    Code:
    result_flt:single=math.ArcTan2(dy,dx);
    Is that even possible? Shouldn't it be?
    Code:
    var result_flt: single;
    begin
      result_flt := math.ArcTan2(dy,dx);
    end;
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •