Percentage
Hey,
So well, I'm confused with percentage since I sucks with math,
I'm trying to get 3% from a int, but it's giving 0.
Screen: http://i.imgur.com/aGDs9lg.png

Code of one of the taxes: GeneralTax = GeneralTax+(PayCheck/100)*5;

Full code:
PHP код:
``` stock RunPaycheck() {     for(new playerid = 0; playerid < MAX_PLAYERS; playerid++) {             if(IsPlayerConnected(playerid)) {             //==[PayCheck]==//             new PayCheck;             if(Player[playerid][Job] == 2) //Mechanic                 PayCheck = random(110-90)+90;             else if(Player[playerid][Job] == 3) //Miner                 PayCheck = random(150-140)+140;             else                 PayCheck = random(50-45)+45;             new paycheck[128];             format(paycheck, 128, "Paycheck: \$%i", PayCheck);             //==[Tax]==//             new GeneralTax;             GeneralTax = GeneralTax+(PayCheck/100)*5;             new generaltax[128];             format(generaltax, 128, "General Tax: -\$%i", GeneralTax);             //==[Houses]==//             new HouseTax, HousesEx;             for(new hid = 0; hid < 500; hid++) {                 if(!isnull(Houses[hid][Owner]) && !strcmp(Houses[hid][Owner], GetPlayerNameEx(playerid))) {                     HouseTax = (PayCheck/100) * 3;                     HousesEx++;                 }             }             new housetax[128];             format(housetax, 128, "House Tax: -\$%i", HouseTax);             //==[Business]==//             new BusinessTax, Business;             for(new bid = 0; bid < 500; bid++) {                 if(!isnull(Stores[bid][Owner]) && !strcmp(Stores[bid][Owner], GetPlayerNameEx(playerid))) {                     BusinessTax = (PayCheck/100) * 3;                     Business++;                 }             }             new businesstax[128];             format(businesstax, 128, "Business Tax: -\$%i", BusinessTax);             //==[Result]==//             new Result;             Result = PayCheck-BusinessTax-HouseTax-GeneralTax;             new result[128];             if(floatround(Result, floatround_round) < 0)                 format(result, 128, "Result: -\$%i", Result);             else                  format(result, 128, "Result: \$%i", Result);             //==[Balance]==//             new Balance[128];             format(Balance, 128, "New Balance: \$%i Old Balance: \$%i", Result+Player[playerid][Bank], Player[playerid][Bank]);             //==[Messages]==//             SendClientMessage(playerid, 0xD1D1D1FF, "_______________[Paycheck]_______________");             SendClientMessage(playerid, 0xD1D1D1FF, generaltax);             if(HousesEx > 0)                 SendClientMessage(playerid, 0xD1D1D1FF, housetax);             if(Business > 0)                 SendClientMessage(playerid, 0xD1D1D1FF, businesstax);             SendClientMessage(playerid, 0xD1D1D1FF, paycheck);             SendClientMessage(playerid, 0xD1D1D1FF, result);             SendClientMessage(playerid, 0xD1D1D1FF, Balance);             SendClientMessage(playerid, 0xD1D1D1FF, "________________________________________");             //==[PayCheck]==//             Player[playerid][Bank] = Result+Player[playerid][Bank];         }     }     GameTextForAll("~g~PayDay", 8000, 1); }  ```
Don't forget that the result is a floating-point number so round its value downwards.

pawn Код:
`GeneralTax = floatround(PayCheck * 0.05, floatround_floor);`
You can also multiply it with 0.05 directly to avoid division. For your example, the paycheck is 45 so the 5% of it is 2.25 which makes GeneralTax to be 2.
Quote:
 Originally Posted by Konstantinos Don't forget that the result is a floating-point number so round its value downwards. pawn Код: `GeneralTax = floatround(PayCheck * 0.05, floatround_floor);` You can also multiply it with 0.05 directly to avoid division. For your example, the paycheck is 45 so the 5% of it is 2.25 which makes GeneralTax to be 2.
Thanks mate, Been looking for something like this

Forum Jump:

Users browsing this thread: 1 Guest(s)