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
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
Round()?
lol
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
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.
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!.
Negative numbers are the only things that'll make Floor and Trunc act differently, right?
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
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.
There are currently 1 users browsing this thread. (0 members and 1 guests)