Converting a float into an integer
#1

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?
Reply
#2

pawn Код:
format( str, 64, "~b~MPH: ~w~%i", speed );
Reply
#3

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.
Reply
#4

pawn Код:
format( str, 64, "~b~MPH: ~w~%i.0", speed );
Try this one.
Reply
#5

11 billion.0. :P
Reply
#6

Use floatround
Reply
#7

floatround(speed)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)