Percentage problem
#1

PHP код:
tax = (GovTax/100)*PlayerInfo[playerid][pSigncheck];//random(50) + 10;
        
format(msizeof(m), "Tax: %i"tax); 
tax returns zero,

GovTax = 10

Full command
PHP код:
CMD:signcheck(playerid,params[]){
    new 
m[512], tax;
    if(
TodayPlayingHour[playerid]>300)
    {
        if(
PlayerInfo[playerid][pSavingMoney] > 0)
        {
            if(
PlayerInfo[playerid][pSavingMoney] >= 50000) return SendClientMessage(playeridCOLOR_YELLOW"You won't recieve anymore interest in saving account, your saving balance has reached maximum.");
            
SavingMoney[playerid] = PlayerInfo[playerid][pSavingMoney]*5/100//Gets 2 percents from the savings, i guess it has to be *PERCENTAGE NUMBER WE WANT and divided by 100
            
PlayerInfo[playerid][pSavingMoney] += 2*SavingMoney[playerid];
        }
        if(
PlayerHaveSigncheck[playerid]==0) return SendClientMessage(playeridCOLOR_RED"There is no active signcheck.");
        
PlayerInfo[playerid][pEXP] += 1;
        
SendClientMessage(playeridCOLOR_GREY"___________________| Signcheck Received |___________________");
        
format(msizeof(m), "Paycheck: $%i"PlayerInfo[playerid][pSigncheck]);
        
SendClientMessage(playeridCOLOR_GREYm);
        
format(msizeof(m), "Savings Bonus: $%i"SavingMoney[playerid]);
        
SendClientMessage(playeridCOLOR_GREYm);
        
SendClientMessage(playeridCOLOR_GREY"Exp: +1");
        
tax = (GovTax/100)*PlayerInfo[playerid][pSigncheck];//random(50) + 10;
        
format(msizeof(m), "Tax: %i"tax);
        
SendClientMessage(playeridCOLOR_GREYm);
        
GiveMoney(playerid, -tax);
        
AvailableGovTax += tax;
        
GiveMoney(playerid,PlayerInfo[playerid][pSigncheck]);
        
PlayerInfo[playerid][pSigncheck] = 0;
        
PlayerHaveSigncheck[playerid]=0;
    }else
    {
        
SendClientMessage(playeridCOLOR_RED"You have to play atleast 5 minutes to obtain check.");
    }
    return 
1;

Reply
#2

Since you are dividing 10 by 100 you are getting a float instead of an integer.
So you will have to change
Quote:

new tax;

to
Quote:

new Float: tax;

For dividing floats you need to use the function:
Quote:

floatdiv(Float:dividend, Float:divisor)

So your code would look like this:
Quote:

tax = floatdiv(GovTax/100)*PlayerInfo[playerid][pSigncheck];
format(m, sizeof(m), "Tax: %f", tax);

You should use the function floatround to convert this float to an integer if you intend to use it that way. https://sampwiki.blast.hk/wiki/Floatround
Reply
#3

Quote:
Originally Posted by justinnater
Посмотреть сообщение
Since you are dividing 10 by 100 you are getting a float instead of an integer.
So you will have to change to
For dividing floats you need to use the function:
So your code would look like this:


You should use the function floatround to convert this float to an integer if you intend to use it that way. https://sampwiki.blast.hk/wiki/Floatround
floatdiv is not neccessary to specifically use, dividing two values/variables when at least one of them has a Float tag will use floatdiv "automatically".
In fact, all float operations in pawn will call the corresponding float* native function since the VM cannot calculate float numbers.

You can just do

Код:
GovTax / 100.0
and it will use floatdiv anyway.
The operators for Float tags are basically macros for these functions.
Reply
#4

Thanks for correcting me, good thing to know.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)