Percent calculation problem
#1

Whats up!

I have a problem with a percent calculation here is the code:

pawn Код:
new amount = (pInfo[i][Cash] / 100) * 0,1;
It gives me this error: expected token: "-identifier-", but found "-integer value-"

Any help would be appreciated!
Reply
#2

You have to use a dot instead of a comma

Код:
new amount = (pInfo[i][Cash] / 100) * 0.1;
Reply
#3

Not working... it now gives me a warning "tag mismatch"
Reply
#4

pawn Код:
new Float:amount = floatmul(floatdiv(float(pInfo[i][Cash]), 100.0), 0.1);
Reply
#5

Quote:
Originally Posted by Gilbonzo
Посмотреть сообщение
Not working... it now gives me a warning "tag mismatch"
Yeah.. forgot that it needs to be a float because of the multiplication..
So "new Float:amount ....."
Reply
#6

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
pawn Код:
new Float:amount = floatmul(floatdiv(float(pInfo[i][Cash]), 100.0), 0.1);
that didn't actually work or whatever I needed the amount was incredibly high it didn't count it correctly. I need 0.1 percent from 15000, but it equals more than ten million
Reply
#7

What exactly do you need it for and want to calculate?
Reply
#8

Well the "What you need it for" part isn't your business and I am just trying to get 0.1 percent from value 15000
Reply
#9

The actual easiest mathematical way to correctly get a percentage is just using a three simple rule (also known as proportions):

Код:
A - B%
C - D%
So, basically:

Код:
15000 - 100%
X - 0.1%
You multiply the number that's on the side of the incognita (X) by the number that's above it, then divide the result for the number in diagonal of it. Make sure to put each type of proprtion on each side, and by this I mean, percentages with percentages, numbers with numbers.

Код:
(0.1*15000)/100 = X
15 = X
There's also a not so mathematical procedure that implies multiplicating:

15000 * 1.5 = 15000 += 50%
15000 * 0.5 = 15000 -= 50%
15000 * 0.9 = 15000 -= 10%
15000 * 0.1 = 15000 -= 90%

But this is only for resting and summing, not to actually get the percentage.
Reply
#10

And how that would be as a code?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)