AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   ... (https://forums.alliedmods.net/showthread.php?t=337361)

 Cristian505 04-15-2022 15:53

...

...

 Moody92 04-15-2022 15:59

Re: Percentage

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  ```

 fysiks 04-15-2022 17:42

Re: Percentage

Quote:
 Originally Posted by Cristian505 (Post 2776926) 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 2776928) 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.

 abdelwahab 04-15-2022 18:47

Re: Percentage

Quote:
 new szMaxValue = 700; // Maximum value new szProgress; // progress new szProgressPercent; // calculating the percent szProgressPercent = ((szUserProgress * szMaxValue) / 100)

 Cristian505 04-15-2022 22:58

Re: Percentage

...

 fysiks 04-16-2022 02:24

Re: Percentage

Quote:
 Originally Posted by Cristian505 (Post 2776949) 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 04-16-2022 05:30

Re: Percentage

Quote:
 Originally Posted by fysiks (Post 2776933) 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.

 Cristian505 04-16-2022 09:10

Re: Percentage

...

 All times are GMT -4. The time now is 12:45.