AlliedModders

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

ironskillz1 01-05-2013 18:43

percent
 
I want to make percent

so this is code is how many Achievements you got
Code:

TotalAchievements[id]
and this code is how many Achievements the plugin got
Code:

iTotalAchievements
So if i got 6 Achievements it looks like this ingame:
You got 6 of 13 Achievements done


And this is the question, how can i make so it look like this
example:
You got 30 % of 100 % Achievements done


Thanks :)

YamiKaitou 01-05-2013 18:45

Re: percent
 
( Total Achievements / Earned Achievements ) * 100 = Percentage

Sylwester 01-05-2013 19:12

Re: percent
 
You made a little mistake and also to make it work with integers the formula should look like this:
100 * Earned Achievements / Total Achievements

ironskillz1 01-05-2013 20:27

Re: percent
 
Can you show me in code version?

fysiks 01-05-2013 21:16

Re: percent
 
Quote:

Originally Posted by Sylwester (Post 1867841)
You made a little mistake and also to make it work with integers the formula should look like this:
100 * Earned Achievements / Total Achievements

That won't work. It will perform integer division which will always be 0 in this case (when earned is less than total). You need to float them first and output a floating point value.

PHP Code:

new Float:percent 100.0 float(earned)/float(total

@Yami, you have total and earned backwards. :)

Sylwester 01-05-2013 22:08

Re: percent
 
Umm, the division has the same priority as multiplication and it executes them in order from left to right, so it will work fine.
PHP Code:

new percent 100 earned/total 


fysiks 01-05-2013 23:17

Re: percent
 
I didn't say anything about order of operations.

3 / 5 = 0
3.0 / 5.0 = 0.6

Both variables need to be converted to floating point values before they can be divided. To get an integer as an output you would need to do this:

PHP Code:

    new percent floatround(float(earned)/float(total)*100.0


rak 01-06-2013 00:07

Re: percent
 
or you can show the decimals only

PHP Code:

client_print(indexprint_chat"Percent: %0.0f", ( float(earned) / float(total) ) *100.0 


Emp` 01-06-2013 00:12

Re: percent
 
@fysiks: You don't need to work with floats as long as you multiply the numerator by 100 first. I think that is what Sylwester was getting at...

xDrugz 01-06-2013 00:39

Re: percent
 
Hey Use Math :D


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

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.