Ok im wondering if i do this, Int(MYFLOAT) does it Round the number to an int like Round() does or does it just remove the decimal? so if its 1.2 or 1.9 it returns 1?
Announcement
Collapse
No announcement yet.
Float -> Int
Collapse
X
-
int() simply chops off the decimal part, so 1.9 would become 1.
Here's an easy and documented way for you to check such things in the future; a commandlet.
Code://==================================================================== // Generic Commandlet. // // Use as follows: // - Open a DOS box. // - Navigate to the UT2004\System folder. // - Enter the following command: // // UCC [package name].[commandlet name] [parameter]... // // package name: // The name of the package containing the commandlet. // // commandlet name: // The name of your commandlet class. If the class name ends in // "commandlet", you may leave that out. The engine will add it. // // parameter: // Optional string parameter. //==================================================================== class XS_Commandlet extends Commandlet; event int Main(string Parameter) { // Whitespace for readability; Log(""); // Replace this line with whatever you wish to display in the DOS // box. Log("Testing " $ Parameter); return 0; } /** Concatenates v to a string in (X,Y,Z) format. */ static final operator(40) string $ (coerce string s, vector v) { local string NewString; NewString = s $ Round(v.X) $ "," $ Round(v.Y) $ "," $ Round(v.Z); return NewString; } /** Concatenates r to a string in (X,Y,Z) format. */ static final operator(40) string $ (coerce string s, rotator r) { local string NewString; NewString = s $ r.Pitch $ "," $ r.Yaw $ "," $ r.Roll; return NewString; }
-
well thats not wat i want, i want it so no matter what the Decimal is and the integer is 1 it will always return 1, 1.12058021 or 1.01 or 1.98 will come back 1, its for my award stats check:
Code:function bool CheckAward(int Param1, int Param2) { if( Param1/Param2 == Int(Param1/Param2) ) return true; else return false; }
Comment
-
I seem to be having a problem.
Code:function bool CheckAward(int Param1, int Param2) { local float f; f = Param1/Param2; if( f == Int(f) ) return true; else return false; }
so wouldnt it be:
Code:function bool CheckAward(int Param1, int Param2) { local float f; f = 1/12; // should be 0.0833 (repeated) if( f == Int(f) ) // if( 0.0833 == 0 ) should be false right? return true; else return false; }
i ran a test with logs:
ScriptLog: Param1=1 Param2=12
ScriptLog: f=0.00
ScriptLog: if( 0.00 == 0 )
it seems i need the float to be longer then 2 decimal places, more then .00 i need more like .000000
Comment
-
I think the engine makes an integer division because you're dividing two integers, and only then decides to make it a float because you're storing the result in a float. You could probably get the engine to make a float right away like this: float(Param1) / Param2. Then it would no longer be an integer division.
Comment
-
I'm not 100% sure, but I think this is how it works:
You try to divide two whole numbers, and the engine gives you a whole number as the result. You try to divide a whole number and a decimal number or two decimal numbrs, the engine gives you a decimal number as the result.
You want to divide two whole numbers, but still get a decimal number as the result. What should you do? Turn one of the whole numbers into a decimal number. You do that in the same way you turned the float into the int earlier on, only the other way around: float(Param1). Now it is treated as a decimal number, and when you divide it by Param2 you will get a decimal number as the result.
Comment
Comment