Results 1 to 10 of 10

Thread: FloatToInt

  1. #1
    Join Date
    Dec 2009
    Posts
    146
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default FloatToInt

    Since there is apparently no FloatToInt or vice versa, then is the only way to accomplish this to convert the float to a string, and then convert the string to an integer? If someone knows a simpler way to do this I would be very grateful.

    JIM

  2. #2
    Join Date
    Jul 2008
    Location
    England
    Posts
    763
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Round()?
    lol

  3. #3
    Join Date
    Feb 2010
    Location
    England
    Posts
    56
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    what are you trying to accomplish?

    for example if I were to say, FloatToInt(3.14) would you want an output of 3?
    if so, last night I was mucking around with SCAR, and looked at the docs, and there is some neat math functions, e.g. Round, Trunc etc.

    hope that kind of helps (i'm really new, don't hate me if I'm wrong )

    EDIT:
    I never refreshed my browser, it appears I got "ninjad" (by quarter of an hour, sorry)

    void_hatred

  4. #4
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    SCAR Code:
    function Round(e: Extended): LongInt;
    Rounds and converts floating point number to integer.

    function Trunc(e: Extended): LongInt;
    Rounds down and converts to integer.

    function Int(e: Extended): LongInt;

    function Floor(X: Extended): Integer;
    Rounds down X to the lowest integer.
    Example:
    Floor(5.4) = 5

    function Ceil(X: Extended): Integer;
    Rounds down X to the highest integer.
    Example:
    Ceil(5.4) = 6
    Last edited by Zyt3x; 02-13-2010 at 09:04 AM.

  5. #5
    Join Date
    Jul 2008
    Location
    England
    Posts
    763
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Zyt3x View Post
    SCAR Code:
    function Round(e: Extended): LongInt;
    Rounds and converts floating point number to integer.

    function Trunc(e: Extended): LongInt;
    Rounds down and converts to integer.

    function Int(e: Extended): LongInt;
    Don't forget Ceil().
    lol

  6. #6
    Join Date
    Feb 2007
    Location
    Het ademt zwaar en moedeloos vannacht.
    Posts
    7,211
    Mentioned
    26 Post(s)
    Quoted
    72 Post(s)

    Default

    One small thing: Trunc and Floor aren't completely the same. Trunc just deletes the decimals, and floor rounds it down.
    So what's the difference, you may ask?
    Lets take a negative number, like -1.2, trunk makes it -1, but floor will round to the lowest (= -2).
    just a bit of 'i-can-script-too' xd
    I made a new script, check it out!.

  7. #7
    Join Date
    Oct 2006
    Location
    ithurtsithurtsithurtsithurts
    Posts
    2,930
    Mentioned
    7 Post(s)
    Quoted
    135 Post(s)

    Default

    Negative numbers are the only things that'll make Floor and Trunc act differently, right?

  8. #8
    Join Date
    Feb 2007
    Location
    Het ademt zwaar en moedeloos vannacht.
    Posts
    7,211
    Mentioned
    26 Post(s)
    Quoted
    72 Post(s)

    Default

    Yup, that's correct.
    I made a new script, check it out!.

  9. #9
    Join Date
    Dec 2009
    Posts
    146
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by void_hatred View Post
    what are you trying to accomplish?

    for example if I were to say, FloatToInt(3.14) would you want an output of 3?
    if so, last night I was mucking around with SCAR, and looked at the docs, and there is some neat math functions, e.g. Round, Trunc etc.

    hope that kind of helps (i'm really new, don't hate me if I'm wrong )
    My main reason for asking is for progress reports. If I want to determine exp per run, or exp per hour, or something like that, if I divide an int, by an int, I don't get an accurate answer. The answer will be truncated. 20/30=0 and stuff like that, which obviously doesn't work. So if I have an int, lets say experience, and I multiply that by a float, lets say exp per bar, as in smithing which might be something like 37.5, so you will end up with a type mismatch error, as you can't do anything with floats and ints together, they just don't comingle well. So the solution I've found is to convert the integer to a string, then convert that string to a float. So instead of my runs counter being an integer as it was originally, it is now a float and I can multiply it by my exp per bar, which is also a float, so that will tell me the correct amount of total exp I have earned while this script was running.

    Hopefully this all makes sense...

    JIM

  10. #10
    Join Date
    Feb 2010
    Location
    England
    Posts
    56
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    It sounds like you want IntToFloat, not FloatToInt (though I can't find IntToFloat being a function)

    however, you could just define both variables to be extended, for example:

    SCAR Code:
    program Jim;

    var
      exp, logs: Extended;
     
    begin
      exp := 37.5; // per tree, etc.
      logs := 5;
      WriteLn(a * b); // 187.5
    end.

    void_hatred
    Last edited by void_hatred; 02-15-2010 at 10:36 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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