SA-MP Forums Per cent calculation
 User Name Remember Me? Password
 New Account Members List Search Today's Posts Mark Forums Read

 Thread Tools Display Modes
 19/12/2009, 06:33 PM #1 Coicatak Huge Clucker   Join Date: Nov 2008 Posts: 318 Reputation: 0 Per cent calculation 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 Code: `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?
 19/12/2009, 06:35 PM #2 beckzy Beta Tester   Join Date: Dec 2006 Posts: 1,214 Reputation: 152 Re: Per cent calculation 30% of 15 Code: `15 / 100 * 30` Basically find 1% by dividing by 100 then multiply by 30 to get 30%. __________________
 19/12/2009, 07:28 PM #3 Joe Staff High-roller   Join Date: Aug 2007 Posts: 2,596 Reputation: 379 Re: Per cent calculation percentages are floats anyway. And if you're trying to get the percentage given two numbers, then do pawn Code: `new Current = 35new Max = 50new Float:percentage = (Current/Max)*100printf("%f%%",percentage);` that would give 70%
 19/12/2009, 07:44 PM #4 Coicatak Huge Clucker   Join Date: Nov 2008 Posts: 318 Reputation: 0 Re: Per cent calculation a float isn't an integer, is it?
 19/12/2009, 11:20 PM #5 Coicatak Huge Clucker   Join Date: Nov 2008 Posts: 318 Reputation: 0 Re: Per cent calculation I've tried pawn Code: `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?
 19/12/2009, 11:45 PM #6 Coicatak Huge Clucker   Join Date: Nov 2008 Posts: 318 Reputation: 0 Re: Per cent calculation Oh it finally works! Thanks a lot ****** And others for trying
 20/12/2009, 12:43 AM #7 DiddyBop Gangsta     Join Date: Aug 2009 Posts: 666 Reputation: 10 Re: Per cent calculation ****** should be kyeman's bitch.
20/12/2009, 01:46 AM   #8
Joe Staff
High-roller

Join Date: Aug 2007
Posts: 2,596
Reputation: 379
Re: Per cent calculation

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 Code: `new Current = 35new Max = 50new Float:percentage = (Current/Max)*100printf("%f%%",percentage);` that would give 70%
No - that still has the same problem!

Code:
```35 / 50 = 0
0 * 100 = 0
0 converted to a float = 0.0```
floatdiv(current,max)*100 =p

 20/12/2009, 09:39 AM #9 Balon Big Clucker   Join Date: Oct 2007 Posts: 108 Reputation: 2 Re: Per cent calculation pawn Code: `new Float:percentage = (35.0 / 50.0) * 100.0;` Simply don't mix types guys.
24/01/2011, 03:40 PM   #10
1D10T
Little Clucker

Join Date: Jan 2011
Location: Netherlands
Posts: 15
Reputation: 0
Re: Per cent calculation

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

Last edited by 1D10T; 24/01/2011 at 05:56 PM. Reason: We got the original lselevator working.

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post pagie1111 Help Archive 2 08/02/2010 02:26 PM RyDeR` Everything and Nothing 2 25/12/2009 11:16 AM Stunterz Server Support 2 13/08/2009 04:37 PM

All times are GMT. The time now is 03:14 AM.

 -- (EN) English -- (RU) Русски SA-MP - Archive - Top