Calculating percentage with float?
#1

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

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

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

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
Reply
#5

oh yea sorry,edited
Reply
#6

Thank you! REP +!

Really appreciate that.
Reply
#7

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


Forum Jump:


Users browsing this thread: 2 Guest(s)