[Pawn] Problem with percentage - Printable Version + open.mp forum (https://forum.open.mp) -- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3) --- Forum: Pawn Scripting (https://forum.open.mp/forumdisplay.php?fid=10) --- Thread: [Pawn] Problem with percentage (/showthread.php?tid=1449) |
Problem with percentage - GospodinX - 2020-12-22 Hi guys I use percentage for many things in my SA-MP server.(discounts,tax etc),but I have some problems with it. For "small" numbers it work pretty nice. Code: Code: new result = PERCENT*PRICE/100; First test: PERCENT: 75 PRICE: 140 000 000 Result:?19100654 Result is ok Second test: PERCENT: 75 PRICE: 340 000 000 Result:?-17698038 Result is wrong Does anyone have idea how I should fix it? RE: Problem with percentage - Pinch - 2020-12-22 Because -2??-1 is the max value a single variable can store and as soon as you can try to go beyond that value, it overflows and starts going backwards... Try price * 0.percentage Ex: 340 000 000 * 0.75 RE: Problem with percentage - GospodinX - 2020-12-22 (2020-12-22, 11:36 AM)Pinch Wrote: Because -2??-1 is the max value a single variable can store and as soon as you can try to go beyond that value, it overflows and starts going backwards... Hm ? RE: Problem with percentage - Pinch - 2020-12-23 My bad, price - (price * 0.75) |