[HELP] Percentage
#1

I know this is a relaly dumb question, but how would I take a percentage off of a %d? Such as 20% off in the script? 10%?

Thanks, REP+
Reply
#2

Float example:

format(string, sizeof(string), "Answer: %0.2f%s!", gServerTestFloat, "%%");

Bold text = percentage symbol in-game ("%"). Remove %s from the format if you're going to remove the bold text.

Is that what you mean?
Reply
#3

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
Float example:

format(string, sizeof(string), "Answer: %0.2f%s!", gServerTestFloat, "%%");

Bold text = percentage symbol in-game ("%"). Remove %s from the format if you're going to remove the bold text.

Is that what you mean?
Unfortunately not. I mean take 20% from HousePrice in something like this:

pawn Код:
Player[playerid][Money] -= Houses[h][HousePrice] // Take 20 percent here;
Reply
#4

Quote:
Originally Posted by BornHuman
Посмотреть сообщение
Unfortunately not. I mean take 20% from HousePrice in something like this:

pawn Код:
Player[playerid][Money] -= Houses[h][HousePrice] // Take 20 percent here;
Oh, why didn't you just say so?

There's different ways to calculate a discount, I'll show you two of them:

1)
pawn Код:
1: discount <- 0.01;
2: discount <- 0.02;
3: discount <- 0.03;
4: discount <- 0.04;
5: discount <- 0.05;
6: discount <- 0.06;
7: discount <- 0.07;
8: discount <- 0.08;
9: discount <- 0.09;
10: discount <- 0.10;
11: discount <- 0.11;
12: discount <- 0.12;
13: discount <- 0.13;
14: discount <- 0.14;
15: discount <- 0.15;
16: discount <- 0.16;
17: discount <- 0.17;
18: discount <- 0.18;
19: discount <- 0.19;
20: discount <- 0.20;
21: discount <- 0.21;
22: discount <- 0.22;
23: discount <- 0.23;
24: discount <- 0.24;
25: discount <- 0.25;
26: discount <- 0.26;
27: discount <- 0.27;
28: discount <- 0.28;
29: discount <- 0.29;
30: discount <- 0.30;
31: discount <- 0.31;
32: discount <- 0.32;
33: discount <- 0.33;
34: discount <- 0.34;
35: discount <- 0.35;
36: discount <- 0.36;
37: discount <- 0.37;
38: discount <- 0.38;
39: discount <- 0.39;
40: discount <- 0.40;
41: discount <- 0.41;
42: discount <- 0.42;
43: discount <- 0.43;
44: discount <- 0.44;
45: discount <- 0.45;
46: discount <- 0.46;
47: discount <- 0.47;
48: discount <- 0.48;
49: discount <- 0.49;
50: discount <- 0.50;
51: discount <- 0.51;
52: discount <- 0.52;
53: discount <- 0.53;
54: discount <- 0.54;
55: discount <- 0.55;
56: discount <- 0.56;
57: discount <- 0.57;
58: discount <- 0.58;
59: discount <- 0.59;
60: discount <- 0.60;
61: discount <- 0.61;
62: discount <- 0.62;
63: discount <- 0.63;
64: discount <- 0.64;
65: discount <- 0.65;
66: discount <- 0.66;
67: discount <- 0.67;
68: discount <- 0.68;
69: discount <- 0.69;
70: discount <- 0.70;
71: discount <- 0.71;
72: discount <- 0.72;
73: discount <- 0.73;
74: discount <- 0.74;
75: discount <- 0.75;
76: discount <- 0.76;
77: discount <- 0.77;
78: discount <- 0.78;
79: discount <- 0.79;
80: discount <- 0.80;
81: discount <- 0.81;
82: discount <- 0.82;
83: discount <- 0.83;
84: discount <- 0.84;
85: discount <- 0.85;
86: discount <- 0.86;
87: discount <- 0.87;
88: discount <- 0.88;
89: discount <- 0.89;
90: discount <- 0.90;
91: discount <- 0.91;
92: discount <- 0.92;
93: discount <- 0.93;
94: discount <- 0.94;
95: discount <- 0.95;
96: discount <- 0.96;
97: discount <- 0.97;
98: discount <- 0.98;
99: discount <- 0.99;
100: discount <- 1;

discount = (cost * discount);
price = cost - discount;
2)
pawn Код:
price = cost - (discount / 100 * cost);
Obviously you'd go with the second option, right? haha

Anyway,
Good luck, mate!
Reply
#5

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
Oh, why didn't you just say so?

There's different ways to calculate a discount, I'll show you two of them:

1)
pawn Код:
1: discount <- 0.01;
2: discount <- 0.02;
3: discount <- 0.03;
4: discount <- 0.04;
5: discount <- 0.05;
6: discount <- 0.06;
7: discount <- 0.07;
8: discount <- 0.08;
9: discount <- 0.09;
10: discount <- 0.10;
11: discount <- 0.11;
12: discount <- 0.12;
13: discount <- 0.13;
14: discount <- 0.14;
15: discount <- 0.15;
16: discount <- 0.16;
17: discount <- 0.17;
18: discount <- 0.18;
19: discount <- 0.19;
20: discount <- 0.20;
21: discount <- 0.21;
22: discount <- 0.22;
23: discount <- 0.23;
24: discount <- 0.24;
25: discount <- 0.25;
26: discount <- 0.26;
27: discount <- 0.27;
28: discount <- 0.28;
29: discount <- 0.29;
30: discount <- 0.30;
31: discount <- 0.31;
32: discount <- 0.32;
33: discount <- 0.33;
34: discount <- 0.34;
35: discount <- 0.35;
36: discount <- 0.36;
37: discount <- 0.37;
38: discount <- 0.38;
39: discount <- 0.39;
40: discount <- 0.40;
41: discount <- 0.41;
42: discount <- 0.42;
43: discount <- 0.43;
44: discount <- 0.44;
45: discount <- 0.45;
46: discount <- 0.46;
47: discount <- 0.47;
48: discount <- 0.48;
49: discount <- 0.49;
50: discount <- 0.50;
51: discount <- 0.51;
52: discount <- 0.52;
53: discount <- 0.53;
54: discount <- 0.54;
55: discount <- 0.55;
56: discount <- 0.56;
57: discount <- 0.57;
58: discount <- 0.58;
59: discount <- 0.59;
60: discount <- 0.60;
61: discount <- 0.61;
62: discount <- 0.62;
63: discount <- 0.63;
64: discount <- 0.64;
65: discount <- 0.65;
66: discount <- 0.66;
67: discount <- 0.67;
68: discount <- 0.68;
69: discount <- 0.69;
70: discount <- 0.70;
71: discount <- 0.71;
72: discount <- 0.72;
73: discount <- 0.73;
74: discount <- 0.74;
75: discount <- 0.75;
76: discount <- 0.76;
77: discount <- 0.77;
78: discount <- 0.78;
79: discount <- 0.79;
80: discount <- 0.80;
81: discount <- 0.81;
82: discount <- 0.82;
83: discount <- 0.83;
84: discount <- 0.84;
85: discount <- 0.85;
86: discount <- 0.86;
87: discount <- 0.87;
88: discount <- 0.88;
89: discount <- 0.89;
90: discount <- 0.90;
91: discount <- 0.91;
92: discount <- 0.92;
93: discount <- 0.93;
94: discount <- 0.94;
95: discount <- 0.95;
96: discount <- 0.96;
97: discount <- 0.97;
98: discount <- 0.98;
99: discount <- 0.99;
100: discount <- 1;

discount = (cost * discount);
price = cost - discount;
2)
pawn Код:
price = cost - (discount / 100 * cost);
Obviously you'd go with the second option, right? haha

Anyway,
Good luck, mate!
Lol yeah! Thanks

REP+
Reply
#6

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
-snip-
Wait a sec, could you put it into context? I can't seem to be able to do it.

pawn Код:
new discount;
                                    if(Player[i][VipLevel] == 2)
                                    {
                                        discount = Houses[h][HousePrice] - // want to get the percent of Houses[h][HousePrice] by 10% (0.10)
                                    }
Reply
#7

pawn Код:
discount = Houses[h][HousePrice] / discountpercent;
If the houseprice is 10, and discountpercent is 10(percent off) then it'll be 90. It's simply a basic mathematical operation.
Reply
#8

Код:
	new 
		discount = floatmul(floatdiv(10, 100), Houses[h][HousePrice]);
		finalprice = Houses[h][HousePrice] - discount
	;
Reply
#9

This could be used to discount different percentages (10 being the percentage):
pawn Код:
Player[playerid][Money] -= Houses[h][HousePrice] - (10 / 100 * Houses[h][HousePrice]);
This is a stand alone way:
pawn Код:
Player[playerid][Money] -= Houses[h][HousePrice] - (0.10 * Houses[h][HousePrice]);
Reply
#10

If you want e.g. 20% of the value then just divide it by 5 (20 * 5 = 100)! Divide it by 10 if you want 10% (10 * 10 = 100) of the value.

So, house price might be $15,000. You want 20% of that, just divide ( / ) it by 5.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)