FloatToInt(float)
浮動小数値を整数値に変換する/小数点以下を切り捨てる
int FloatToInt( float fFloat );
Parameters
fFloat
整数型に変えたい浮動小数値
Description
fFloatの浮動小数型の値を整数値に変える。整数型は小数位をサポートしていないため、小数点以下の数値は結果的に切り捨てられる。四捨五入はされない。
Remarks
BioWareの文章には誤って、四捨五入されると記述されている。
Version
1.22
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);
int iNegSum = iAddAngles(0 - iA1, 0 - iA2);
// this tests the negatives added together
//(-10 + -10 = -20 = 340 degrees)
SendMessageToPC(GetFirstPC(), IntToString(iSum));
SendMessageToPC(GetFirstPC(), IntToString(iNegSum));
SetLocalInt(OBJECT_SELF, "a1", iA1 + 10);
SetLocalInt(OBJECT_SELF, "a2", iA2 + 10);
}
// this function return the normalized sum of two angles
// (will always be a positive angle value b/w 0 and 359).
int iAddAngles(int iAngleOne, int iAngleTwo)
{
int iAngleSum = (iAngleOne + iAngleTwo);
int iNormalAngleSum = iAngleSum - (360 * FloatToInt(iAngleSum/360.0));
if (iNormalAngleSum >= 0)
{
return iNormalAngleSum;
}
else
{
return 360 + iNormalAngleSum;
}
}
See Also
| functions: | FloatToString | IntToFloat |
| categories: | Type Casting/Conversion Functions |
author: Charles Feduke, JP team: ngtaicho
Send comments on this topic.