Per cent calculation - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Per cent calculation (
/showthread.php?tid=114524)
Per cent calculation -
Coicatak - 19.12.2009
Hi, i've tried with several methods but i've NEVER to calculate a percentage on SAMP. For example if I want to find 30% of 15 i find 0.
Here is one of the method I used:
pawn Код:
new Float: caution = CarInfo[car][cPrice]*0.3;
printf("%d. %0.1f.", CarInfo[car][cPrice], floatround(caution)); //cPrice = 15 and floatround(caution) = 0 where it should be 4.5
Any help?
Re: Per cent calculation -
beckzy - 19.12.2009
30% of 15
Basically find 1% by dividing by 100 then multiply by 30 to get 30%.
Re: Per cent calculation -
Joe Staff - 19.12.2009
percentages are floats anyway. And if you're trying to get the percentage given two numbers, then do
pawn Код:
new Current = 35
new Max = 50
new Float:percentage = (Current/Max)*100
printf("%f%%",percentage);
that would give 70%
Re: Per cent calculation -
Coicatak - 19.12.2009
a float isn't an integer, is it?
Re: Per cent calculation -
Coicatak - 19.12.2009
I've tried
pawn Код:
new Float: caution = ((CarInfo[car][cPrice]*30)/100);
printf("%d. %0.1f", CarInfo[car][cPrice], floatround(caution)); //price = 15 and caution's still 0
What's wrong?
Re: Per cent calculation -
Coicatak - 19.12.2009
Oh it finally works! Thanks a lot ******

And others for trying
Re: Per cent calculation -
DiddyBop - 19.12.2009
****** should be kyeman's bitch.
Re: Per cent calculation -
Joe Staff - 20.12.2009
Quote:
Originally Posted by Y_Leѕѕ
Quote:
Originally Posted by Joe Staff
percentages are floats anyway. And if you're trying to get the percentage given two numbers, then do
pawn Код:
new Current = 35 new Max = 50 new Float:percentage = (Current/Max)*100 printf("%f%%",percentage);
that would give 70%
|
No - that still has the same problem!
Код:
35 / 50 = 0
0 * 100 = 0
0 converted to a float = 0.0
|
floatdiv(current,max)*100 =p
Re: Per cent calculation -
Balon - 20.12.2009
pawn Код:
new Float:percentage = (35.0 / 50.0) * 100.0;
Simply don't mix types guys.
Re: Per cent calculation -
1D10T - 24.01.2011
Hi all,
I was wandering if you can calculate the time of a Timer. If so I could create timers that calculate how long they have to roll depending on what FloorLevel you are and which FloorLevel you want to go to. I haven't figured out the correct formula to calculate this but is it possible? Because then you can use one timer with variable that change the duration of the timer.
Quote:
if(floor == 0 || FloorLevel != 0)
{
SendClientMessage( playerid, WHITE, "You selected the Ground Floor" );
MoveDynamicObject(Elevator, 1786.678100, -1303.459472, 14.551476, 10);
ElevatorState = ELEVATOR_STATE_MOVING;
SetTimer("Floor0", [Calculation], 0);
return 1;
}
|