FloatToInt

FloatToInt(float)
Converts a number with a decimal into a number without one.

int FloatToInt(    float fFloat );

Parameters

 * int fFloat
 * The float to convert to an integer.

Description
Convert fFloat into the nearest integer. Since an integer does not support precision (that is, decimal places), the precision is lost (truncated). No rounding of the number occurs.

Remarks
Marked incorrectly by BioWare documentation as rounding not truncating the decimal value. In other words, both of the floats 2.001 and 2.999 will be converted to the integer 2.

Version
1.61

Example
// example courtesy of Ken Vargo // normalizing angles // variation of an example introduced by Vane // when it was realized that FloatToInt acts like // TRUNC in MS Excel rather than INT. int iAddAngles(int iAngleOne, int iAngleTwo); void main {    int iA1 = GetLocalInt (OBJECT_SELF, "a1" ); int iA2 = GetLocalInt (OBJECT_SELF, "a2" ); int iSum = iAddAngles(iA1, iA2); <font color="#0000ff">int iNegSum = iAddAngles( - iA1, - iA2); <font color="#007f00">// this tests the negatives added together <font color="#007f00">//(-10 + -10 = -20 = 340 degrees) SendMessageToPC(GetFirstPC, IntToString(iSum)); SendMessageToPC(GetFirstPC, IntToString(iNegSum)); SetLocalInt(<font color="#0000ff">OBJECT_SELF, <font color="#00007f">"a1" , iA1 + <font color="#7f007f">10 ); SetLocalInt(<font color="#0000ff">OBJECT_SELF, <font color="#00007f">"a2" , iA2 + <font color="#7f007f">10 ); } <font color="#007f00">// this function return the normalized sum of two angles <font color="#007f00">// (will always be a positive angle value b/w 0 and 359). <font color="#0000ff">int iAddAngles(<font color="#0000ff">int iAngleOne, <font color="#0000ff">int iAngleTwo) {    <font color="#0000ff">int iAngleSum = (iAngleOne + iAngleTwo); <font color="#0000ff">int iNormalAngleSum = iAngleSum - (<font color="#7f007f">360 * FloatToInt(iAngleSum/360.0)); <font color="#0000ff">if (iNormalAngleSum >= ) {        <font color="#0000ff">return iNormalAngleSum; }    <font color="#0000ff">else {        <font color="#0000ff">return  <font color="#7f007f">360 + iNormalAngleSum; } }