Converting a float into an integer - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Converting a float into an integer (
/showthread.php?tid=378652)
Converting a float into an integer -
2KY - 18.09.2012
pawn Код:
forward UpdateSpeedo( );
public UpdateSpeedo ( )
{
for( new u; u < MAX_PLAYERS; u ++ )
{
if( InCar [ u ] == true )
{
new
Float:speed,
str [ 64 ];
speed = GetPlayerSpeed( u, false );
format( str, 64, "~b~MPH: ~w~%02f", speed );
PlayerTextDrawSetString( u, Speedo [ u ], str );
}
}
return true;
}
pawn Код:
stock Float:GetPlayerSpeed(playerid, bool:KMH)
{
new Float:Speed, Float:vX, Float:vY, Float:vZ;
if(!IsPlayerInAnyVehicle(playerid)) GetPlayerVelocity(playerid, vX, vY, vZ);
else GetVehicleVelocity(GetPlayerVehicleID(playerid), vX, vY, vZ);
Speed = floatsqroot(((vX*vX)+(vY*vY))+(vZ*vZ));
return KMH ? (Speed*100.0) : (Speed*62.1371);
}
But right now, it reads "MPH: 59.398217387218"
I would like it to just be 59. I tried %0.2f and it didn't work, so what do I do?
Re: Converting a float into an integer -
AtItsMax - 18.09.2012
pawn Код:
format( str, 64, "~b~MPH: ~w~%i", speed );
Re: Converting a float into an integer -
2KY - 18.09.2012
Quote:
Originally Posted by AtItsMax
pawn Код:
format( str, 64, "~b~MPH: ~w~%i", speed );
|
Once I take off in a vehicle, I'm going around 11 billion miles per hour. I don't think that's the solution I'm looking for. lol.
Re: Converting a float into an integer -
AtItsMax - 18.09.2012
pawn Код:
format( str, 64, "~b~MPH: ~w~%i.0", speed );
Try this one.
Re: Converting a float into an integer -
2KY - 18.09.2012
11 billion.0. :P
Re: Converting a float into an integer -
ViniBorn - 18.09.2012
Use
floatround
Re: Converting a float into an integer -
ReVo_ - 18.09.2012
floatround(speed)