floatround?
#1

What is wrong at this command?

PHP код:
CMD:fill(playeridparams[])
{
    if(
IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        new 
fillstring[128];
        
formatfillstringsizeof(fillstring), "You payed {FFFFFF}%d"ORANGESV"$ to refill your car's fuel."floatround(((100-CarFuel[GetPlayerVehicleID(playerid)])/100)*BusinessInfo[18][bFee]));
        
BusinessInfo[18][bMoney] += floatround(((100-CarFuel[GetPlayerVehicleID(playerid)])/100 )*BusinessInfo[18][bFee]);
        
GivePlayerTheMoney(playerid, - floatround(((100-CarFuel[GetPlayerVehicleID(playerid)])/100)*BusinessInfo[18][bFee]));
        
SCM(playeridORANGESfillstring);
        foreach(
Playeri)
        {
            if(
GetPlayerVehicleID(i) == GetPlayerVehicleID(playerid))
            {
                
KillTimer(CarTimer[playerid]);
                
TogglePlayerControllable(i0);
                
FillTimer[playerid] = SetTimerEx("Fill"250false"i"i);
            }
        }
    }
    else 
SCM(playeridCOLOR_DGREY"You are not driving a car.");
    return 
1;

It fills my vehicle but it won't take my money.
It says "You payed 0$ ro refill your car's fuel."
Is there a problem because of floatround?

BusinessFee = 5000, so:
Example: if I have 20/100 fuel I want to take my money 80% from BusinessFee, so 80/100*5000
Another example: if I have 70/100 fuel I want to take my money 30% from BusinessFee, so 30/100*5000

Can anyone help me? thanks!
Reply
#2

Well you used integer instead of floats therefor it would always return 0

Add .0 after each 100, also use a variable, just looks silly to do the calculation three times
Reply
#3

Great read: http://stackoverflow.com/a/3602857
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)