Forum server hiccuped while posting this and now there's a corpse thread in the list
http://forums.alliedmods.net/showthread.php?t=106631
Strip a float to any number of decimal places, up to 1.
(There's no sense it stripping ALL places with this function, since you just could use RoundToFloor and IntToString for this)
Usage:
PHP Code:
new String:strPI[64];
FloatToCutString(3.141592653589793, strPI, sizeof(strPI), 2)
PrintToChatAll("PI = %s", strPI);
Result: PI = 3,14
PHP Code:
bool:FloatToCutString(Float:value, String:Target[], TargetSize, DecPlaces)
{
if(DecPlaces < 1)
return false;
new Float:fBuffer = value, String:Buffer[255], String:Buffer2[255];
new Ganz = RoundToFloor(fBuffer); //strip integer from decimal places
fBuffer = FloatFraction(fBuffer); //strip decimal places from integer
FloatToString(fBuffer, Buffer, (3+DecPlaces)); //cut decimal places to desired (2 places = 5 characters (0,xx\n)
strcopy(Buffer2, sizeof(Buffer2), Buffer[2]); //strip decimal places string from '0,'-prefix
Format(Buffer, sizeof(Buffer), "%i,%s",Ganz,Buffer2);
strcopy(Target, TargetSize, Buffer);
return true;
}
__________________