Per cent calculation
#1

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?
Reply
#2

30% of 15

Код:
15 / 100 * 30
Basically find 1% by dividing by 100 then multiply by 30 to get 30%.
Reply
#3

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%
Reply
#4

a float isn't an integer, is it?
Reply
#5

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?
Reply
#6

Oh it finally works! Thanks a lot ******
And others for trying
Reply
#7

****** should be kyeman's bitch.
Reply
#8

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
Reply
#9

pawn Код:
new Float:percentage = (35.0 / 50.0) * 100.0;
Simply don't mix types guys.
Reply
#10

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;
}

Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)