SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 19/12/2009, 05:33 PM   #1
Coicatak
Huge Clucker
 
Join Date: Nov 2008
Posts: 318
Reputation: 0
Default 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?
Coicatak is offline  
Old 19/12/2009, 05:35 PM   #2
beckzy
Beta Tester
 
Join Date: Dec 2006
Posts: 1,269
Reputation: 168
Default 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%.
__________________
beckzy is offline  
Old 19/12/2009, 06:28 PM   #3
Joe Staff
High-roller
 
Join Date: Aug 2007
Posts: 2,593
Reputation: 379
Default 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 = 35
new Max = 50
new Float:percentage = (Current/Max)*100
printf("%f%%",percentage);
that would give 70%
Joe Staff is offline  
Old 19/12/2009, 06:44 PM   #4
Coicatak
Huge Clucker
 
Join Date: Nov 2008
Posts: 318
Reputation: 0
Default Re: Per cent calculation

a float isn't an integer, is it?
Coicatak is offline  
Old 19/12/2009, 10:20 PM   #5
Coicatak
Huge Clucker
 
Join Date: Nov 2008
Posts: 318
Reputation: 0
Default 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?
Coicatak is offline  
Old 19/12/2009, 10:45 PM   #6
Coicatak
Huge Clucker
 
Join Date: Nov 2008
Posts: 318
Reputation: 0
Default Re: Per cent calculation

Oh it finally works! Thanks a lot ******
And others for trying
Coicatak is offline  
Old 19/12/2009, 11:43 PM   #7
DiddyBop
Gangsta
 
DiddyBop's Avatar
 
Join Date: Aug 2009
Posts: 666
Reputation: 10
Default Re: Per cent calculation

****** should be kyeman's bitch.
DiddyBop is offline  
Old 20/12/2009, 12:46 AM   #8
Joe Staff
High-roller
 
Join Date: Aug 2007
Posts: 2,593
Reputation: 379
Default 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 = 35
new Max = 50
new Float:percentage = (Current/Max)*100
printf("%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
Joe Staff is offline  
Old 20/12/2009, 08:39 AM   #9
Balon
Big Clucker
 
Join Date: Oct 2007
Posts: 108
Reputation: 2
Default Re: Per cent calculation

pawn Code:
new Float:percentage = (35.0 / 50.0) * 100.0;
Simply don't mix types guys.
Balon is offline  
Old 24/01/2011, 02:40 PM   #10
1D10T
Little Clucker
 
Join Date: Jan 2011
Location: Netherlands
Posts: 15
Reputation: 0
Default 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 04:56 PM. Reason: We got the original lselevator working.
1D10T is offline  
 

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Time calculation pagie1111 Help Archive 2 08/02/2010 01:26 PM
Date to Day calculation Help!! RyDeR` Everything and Nothing 2 25/12/2009 10:16 AM
Keep server running on Cent OS Stunterz Server Support 2 13/08/2009 03:37 PM


All times are GMT. The time now is 01:22 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.