Raised This Month: $ Target: $400
 0% 

percent


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ironskillz1
AlliedModders Donor
Join Date: Jul 2012
Location: Sweden
Old 01-05-2013 , 18:43   percent
Reply With Quote #1

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
__________________
I have many private and unique plugins for Jailbreak and Hide'N'Seek. PM me for more info.

Pm me.

Check out my roulette site.
ironskillz1 is offline
Send a message via Skype™ to ironskillz1
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 01-05-2013 , 18:45   Re: percent
Reply With Quote #2

( Total Achievements / Earned Achievements ) * 100 = Percentage
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).

Last edited by YamiKaitou; 01-05-2013 at 18:45.
YamiKaitou is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 01-05-2013 , 19:12   Re: percent
Reply With Quote #3

You made a little mistake and also to make it work with integers the formula should look like this:
100 * Earned Achievements / Total Achievements
__________________
Impossible is Nothing
Sylwester is offline
ironskillz1
AlliedModders Donor
Join Date: Jul 2012
Location: Sweden
Old 01-05-2013 , 20:27   Re: percent
Reply With Quote #4

Can you show me in code version?
__________________
I have many private and unique plugins for Jailbreak and Hide'N'Seek. PM me for more info.

Pm me.

Check out my roulette site.
ironskillz1 is offline
Send a message via Skype™ to ironskillz1
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-05-2013 , 21:16   Re: percent
Reply With Quote #5

Quote:
Originally Posted by Sylwester View Post
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.
__________________

Last edited by fysiks; 01-05-2013 at 21:17.
fysiks is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 01-05-2013 , 22:08   Re: percent
Reply With Quote #6

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 
__________________
Impossible is Nothing
Sylwester is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-05-2013 , 23:17   Re: percent
Reply With Quote #7

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
__________________
fysiks is offline
rak
Veteran Member
Join Date: Oct 2011
Location: banned country
Old 01-06-2013 , 00:07   Re: percent
Reply With Quote #8

or you can show the decimals only

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

www.amxmodx-es.com

Steam: Luchokoldo

Last edited by rak; 01-06-2013 at 00:08.
rak is offline
Send a message via MSN to rak Send a message via Skype™ to rak
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 01-06-2013 , 00:12   Re: percent
Reply With Quote #9

@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...
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
xDrugz
Senior Member
Join Date: Jul 2011
Location: return 4;
Old 01-06-2013 , 00:39   Re: percent
Reply With Quote #10

Hey Use Math
__________________
xDrugz is offline
Reply



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 13:45.


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