SA-MP Forums Archive
Calculating percentage with float? - 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: Calculating percentage with float? (/showthread.php?tid=510643)



Calculating percentage with float? - Dokins - 01.05.2014

pawn Код:
CalculateTax(amount, Float:percentage)
{
    new cash;
    cash = (amount / 100) * percentage;
    return cash;
}
So I have this small function, it returns tag mismatch on the 'cash = ' line and I can't be certain why. Could anyone advise me as to why this might be? Also, based on your answer: The possibility of calculating something like:

30.5% is it possible?


Re: Calculating percentage with float? - XK - 01.05.2014

pawn Код:
CalculateTax(amount, Float:percentage)
{
    return amount / 100 * percentage;
}
tried it in a command and it worked for me


Re: Calculating percentage with float? - Marricio - 01.05.2014

pawn Код:
CalculateTax(amount, Float:percentage)
{
    new Float:cash;
    cash = (amount / 100) * percentage;
    return floatround(cash, floatround_round);
}



Re: Calculating percentage with float? - Patrick - 01.05.2014

Quote:
Originally Posted by XK
Посмотреть сообщение
remove the () around amount/ 100 so it will be:
pawn Код:
CalculateTax(amount, Float:percentage)
{
    new cash;
    cash = amount / 100 * percentage;
    return cash;
}
tried it and it didnt show anything
It compiled properly because you did not use the function but try using it and you will get mismatch tag.

Anyways I don't get why the warning occurs on Floatercentage anyways you don't need to declare a new variable you can do it like this.

pawn Код:
CalculateTax(amount, Float:percentage)
    return (amount / 100) * (_:percentage);
EDIT:

@Marricio - Try using the function you wrote, it prints 0.0


Re: Calculating percentage with float? - XK - 01.05.2014

oh yea sorry,edited


Re: Calculating percentage with float? - Dokins - 01.05.2014

Thank you! REP +!

Really appreciate that.


Re: Calculating percentage with float? - Marricio - 01.05.2014

Quote:
Originally Posted by Patrick_
Посмотреть сообщение
It compiled properly because you did not use the function but try using it and you will get mismatch tag.

Anyways I don't get why the warning occurs on Floatercentage anyways you don't need to declare a new variable you can do it like this.

pawn Код:
CalculateTax(amount, Float:percentage)
    return (amount / 100) * (_:percentage);
EDIT:

@Marricio - Try using the function you wrote, it prints 0.0
My bad :P, didn't think of using that tag..