Rules FAQ Members List Search Register Login

 Raised This Month: \$ Target: \$400 0%

Author Message
Cristian505
Senior Member
Join Date: Oct 2020
 04-15-2022 , 15:53   ... #1 ... Last edited by Cristian505; 08-10-2022 at 14:10.
Moody92
Veteran Member
Join Date: May 2011
Location: Oman
 04-15-2022 , 15:59   Re: Percentage #2 Post your code, if you make the 1000 a variable it'd be better PHP Code: ``` new Float:total = 1000.0 // Totalnew Float:cProgress = 900.0 // Current progress, I am assigning numbers here just for examplenew Float:cParam // calculation parametercParam = (cProgress / total) * 100client_print(id, print_chat, "You have passed %.0f%%%% from %f", cParam, total) // the %%%% is to print the % in chat  ``` Last edited by Moody92; 04-16-2022 at 05:27.
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
04-15-2022 , 17:42   Re: Percentage
#3

Quote:
 Originally Posted by Cristian505 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 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(id, print_chat, "You have passed %d%%%% from %d", cParam, total) // 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.
abdelwahab
Member
Join Date: Aug 2019
04-15-2022 , 18:47   Re: Percentage
#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.
Cristian505
Senior Member
Join Date: Oct 2020
 04-15-2022 , 22:58   Re: Percentage #5 ... Last edited by Cristian505; 08-10-2022 at 14:10.
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
04-16-2022 , 02:24   Re: Percentage
#6

Quote:
 Originally Posted by Cristian505 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.
__________________
Moody92
Veteran Member
Join Date: May 2011
Location: Oman
04-16-2022 , 05:30   Re: Percentage
#7

Quote:
 Originally Posted by fysiks 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.
Cristian505
Senior Member
Join Date: Oct 2020
 04-16-2022 , 09:10   Re: Percentage #8 ... Last edited by Cristian505; 08-10-2022 at 14:10.

 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
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Server Discussion     Source Servers (SRCDS)     HL1 Servers (HLDS) AMX Mod X     News     Bug Reports     General     Off-Topic     Plugins         Suggestions / Requests         Approved Plugins         New Plugin Submissions         Unapproved/Old Plugins         Translation Request         High-Traffic Plugins             GunGame             UAIO (Ultimate All-In-One Plugin)             xREDIRECT             CSDM             AMX Super             RuneMod             Zombie Plague Mod             SuperHero Mod                 News                 Tech Support                 Scripting Help                 Off-Topic / General Chat                 Heroes                     Suggestions / Requests                     Approved Heroes                     New Submissions                     Unapproved/Old Heroes                         Module Heroes                     SuperHero Mod Stats - By 123                 (OLD) Bug Reports     Scripting         Scripting Help         Code Snippets/Tutorials         Module Coding     Donor Access SourceMod     News     General     Plugins         Plugins         Unapproved Plugins         Plugin/Gameplay Ideas and Requests         High-Traffic Plugins             SourceMod Anti-Cheat             Zombie:Reloaded             SourceBans / SourceBans++             VSH / Freak Fortress             Store             SM_Hosties             HLstatsX:CE     Scripting     Extensions     Snippets and Tutorials     Donor Access     Metamod: Source         Metamod:Source Plugins         Metamod:Source Questions         Coding MM:S Plugins & SM Extensions Hosted Stuff     Asherkin's Plugins         TFDodgeball         TF2Items         SteamTools     Bail's Plugins         CSDM         CS:S DM Off-Topic & Trash     Off-Topic     Trash

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

 DMCA - Archive - Top