Raised This Month: $ Target: $400
 0% 

...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Cristian505
Senior Member
Join Date: Oct 2020
Old 04-15-2022 , 15:53   ...
Reply With Quote #1

...

Last edited by Cristian505; 08-10-2022 at 14:10.
Cristian505 is offline
Moody92
Veteran Member
Join Date: May 2011
Location: Oman
Old 04-15-2022 , 15:59   Re: Percentage
Reply With Quote #2

Post your code, if you make the 1000 a variable it'd be better

PHP Code:
new Float:total 1000.0 // Total
new Float:cProgress 900.0 // Current progress, I am assigning numbers here just for example

new Float:cParam // calculation parameter

cParam = (cProgress total) * 100

client_print
(idprint_chat"You have passed %.0f%%%% from %f"cParamtotal// the %%%% is to print the % in chat 

Last edited by Moody92; 04-16-2022 at 05:27.
Moody92 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-15-2022 , 17:42   Re: Percentage
Reply With Quote #3

Quote:
Originally Posted by Cristian505 View Post
Is there a way to get the percentage between two numbers?
I mean something like 1000 - 100 = 90% from 1000
"You have passed 90% from 1000"
Yes, it's called division.

Quote:
Originally Posted by Moody92 View Post
Post your code, if you make the 1000 a variable it'd be better

PHP Code:
new total 1000 // Total
new cProgress 900 // Current progress, I am assigning numbers here just for example

new cParam // calculation parameter

cParam = ((total cProgress) / total)*100

client_print
(idprint_chat"You have passed %d%%%% from %d"cParamtotal// the %%%% is to print the % in chat 
No, that is incorrect for two reasons. First, to get the percentage of the total progress, you simply divide the actual value by the total value (cProgress/Total)*100.

The other thing is that you're using integers so you are doing integer division which will means that cProgress / Total will always result in 0 provided that cProgress is less than Total.

To be able to do this, you need to convert to floating point values before doing the division. Alternatively, if you don't need the full precision, you can use integer division but you need to multiply cProgress by 100 first and then divide by Total: (cProgress * 100) / Total. This will effectively be the truncated value of the method using floating point values.
__________________

Last edited by fysiks; 04-15-2022 at 17:51.
fysiks is offline
abdelwahab
Member
Join Date: Aug 2019
Old 04-15-2022 , 18:47   Re: Percentage
Reply With Quote #4

Quote:
new szMaxValue = 700; // Maximum value
new szProgress; // progress
new szProgressPercent; // calculating the percent

szProgressPercent = ((szUserProgress * szMaxValue) / 100)

Last edited by abdelwahab; 04-15-2022 at 19:02.
abdelwahab is offline
Cristian505
Senior Member
Join Date: Oct 2020
Old 04-15-2022 , 22:58   Re: Percentage
Reply With Quote #5

...

Last edited by Cristian505; 08-10-2022 at 14:10.
Cristian505 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-16-2022 , 02:24   Re: Percentage
Reply With Quote #6

Quote:
Originally Posted by Cristian505 View Post
I know this formula but the problem is that this doesnt work on amxx for some reason, i mean doesnt matter what value i put in it, it just gives 0.
Because you didn't read my post.
__________________
fysiks is offline
Moody92
Veteran Member
Join Date: May 2011
Location: Oman
Old 04-16-2022 , 05:30   Re: Percentage
Reply With Quote #7

Quote:
Originally Posted by fysiks View Post
Yes, it's called division.



No, that is incorrect for two reasons. First, to get the percentage of the total progress, you simply divide the actual value by the total value (cProgress/Total)*100.

The other thing is that you're using integers so you are doing integer division which will means that cProgress / Total will always result in 0 provided that cProgress is less than Total.

To be able to do this, you need to convert to floating point values before doing the division. Alternatively, if you don't need the full precision, you can use integer division but you need to multiply cProgress by 100 first and then divide by Total: (cProgress * 100) / Total. This will effectively be the truncated value of the method using floating point values.
Corrected. I just went about settings float points all around.

Though the alternative point can do the job. I am not sure how precise the OP wants it.

Last edited by Moody92; 04-16-2022 at 05:34.
Moody92 is offline
Cristian505
Senior Member
Join Date: Oct 2020
Old 04-16-2022 , 09:10   Re: Percentage
Reply With Quote #8

...

Last edited by Cristian505; 08-10-2022 at 14:10.
Cristian505 is offline
Reply


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

Forum Jump


All times are GMT -4. The time now is 00:40.


Powered by vBulletin®
Copyright ©2000 - 2022, vBulletin Solutions, Inc.
Theme made by Freecode