Simple SAMP Math Symbols Question
#1

pawn Код:
if(PlayerInfo[i][pSavings] >= 50000)
                {
                    new savings = ((5/10)/100)*(PlayerInfo[i][pSavings]);
                    PlayerInfo[i][pSavings] += savings;
                    format(string,sizeof(string),"Your savings grew with 0.5 percent,total: %d",PlayerInfo[i][pSavings]);
                    SendClientMessage(i,COLOR_GREY,string);
                }
How to do that calcules cuz it doesn't work .
I need this fast.I need the Savings account to raise every payday with 0.5%
Reply
#2

PlayerInfo[i][pSavings]*100/5

will calculate 5% of 'pSavings,' if my math is right.

EDIT: Close enough, I suck at maths.
Reply
#3

tag savings as a float or use floatround, and force the compiler to treat the calculation as a float. 5/10=0.5 = 0 as a float, and 0*x=0.

new savings = floatround(0.05*(PlayerInfo[i][pSavings]));


@Calg00ne: Yours will just multiply the value with 20 It would be the other way round: (PlayerInfo[i][pSavings]/100)*5
Reply
#4

Thanks all xD
It worked
Reply
#5

Quote:
Originally Posted by ******
Посмотреть сообщение
Or just rearrange:

Код:
a = PlayerInfo[i][pSavings]
b = ((5 / 10) / 100) * a

- In integer maths 5 / 10 = 0...

- Remove unneeded brackets:
b = 5 / 10 / 100 * a

- Move operators about because they all have the same precedence:
b = 5 * a / 10 / 100

- Group operators:
b = 5 * a / (10 * 100)

- Result:
b = 5 * a / 1000
Despite the fact that's the same equation in theory, it can give a different result in integer maths because you're doing the multiplication last.
****** beat me to it.
Jk...
I had the same thought as calg00ne. :S
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)