dreamwest Posted June 19, 2009 Share Posted June 19, 2009 I know ive done this in school but im trying to get a percentage of 100 i have always 2 numbers: 7 and 3 $total = (7 * 3 ) /100 ; // is 0.21 aka 21% Bt what happens with larger numbers like this below the same function goes crazy 3456 and 39 Quote Link to comment https://forums.phpfreaks.com/topic/162888-i-did-this-in-school/ Share on other sites More sharing options...
Jibberish Posted June 19, 2009 Share Posted June 19, 2009 Crazy in what way? if you use numbers like that your going to get a percent over 100. i.e with those ones it will be 1347.84% Quote Link to comment https://forums.phpfreaks.com/topic/162888-i-did-this-in-school/#findComment-859472 Share on other sites More sharing options...
joel24 Posted June 19, 2009 Share Posted June 19, 2009 i always used $total = (mark / totalPossible) * 100; Quote Link to comment https://forums.phpfreaks.com/topic/162888-i-did-this-in-school/#findComment-859475 Share on other sites More sharing options...
dreamwest Posted June 19, 2009 Author Share Posted June 19, 2009 Crazy in what way? if you use numbers like that your going to get a percent over 100. i.e with those ones it will be 1347.84% Yeah thats why its crazy. I need to show a percentage like 63% with max of 100% not 1347.84% Can anyone see a simple way of doing it? Ok if theres 10 ppl and 7 say yes and 3 say no - what percentage says yes Answer : 23% But what if theres 1230 ppl and 14 say yes and 1216 say no , what percentage says yes. This is what im after Quote Link to comment https://forums.phpfreaks.com/topic/162888-i-did-this-in-school/#findComment-859482 Share on other sites More sharing options...
Dathremar Posted June 19, 2009 Share Posted June 19, 2009 Ok if theres 10 ppl and 7 say yes and 3 say no - what percentage says yes Answer : 23% That doesn't make any sense. But if You want to make a percentage of something you need to know whats the max ie. 10 ppl 7 say yes 3 say no so 7*1/10 = 0.7 * 100 = 70% yes ppl 3 * 1 / 10 = 0.3 * 100 = 30% no ppl ie2. 1230 ppl and 14 say yes and 1216 1216*100 * 1/1230 = yes percentage 14 *100 1/1230 = no percentage Hope you understand this Quote Link to comment https://forums.phpfreaks.com/topic/162888-i-did-this-in-school/#findComment-859486 Share on other sites More sharing options...
dreamwest Posted June 19, 2009 Author Share Posted June 19, 2009 Ezxcellent. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/162888-i-did-this-in-school/#findComment-859496 Share on other sites More sharing options...
.josh Posted June 19, 2009 Share Posted June 19, 2009 Dude what do they teach you kids in school these days? They obviously aren't teaching even basic math.. should just cut to the chase and teach you how to hold a spatula and flip a burger so you'll be prepared for your future career. What's really sad is that I'm not joking. I used to manage a fastfood joint and you'd be surprised at how many people failed at even doing stuff like that. Quote Link to comment https://forums.phpfreaks.com/topic/162888-i-did-this-in-school/#findComment-859563 Share on other sites More sharing options...
MadTechie Posted June 19, 2009 Share Posted June 19, 2009 Mc D's maybe a little advanced, I got a burger and had to complain as the cheese was on the bottom with no bottom bun! The guy said "sorry, that guy is new" I mean WTF.. its a burger ! Quote Link to comment https://forums.phpfreaks.com/topic/162888-i-did-this-in-school/#findComment-859578 Share on other sites More sharing options...
EchoFool Posted June 19, 2009 Share Posted June 19, 2009 Dude what do they teach you kids in school these days? They obviously aren't teaching even basic math.. should just cut to the chase and teach you how to hold a spatula and flip a burger so you'll be prepared for your future career. What's really sad is that I'm not joking. I used to manage a fastfood joint and you'd be surprised at how many people failed at even doing stuff like that. Calm down for all you know he could be a youngster, in which case hes not doing bad having a go at PHP (though it does depend on age).... Quote Link to comment https://forums.phpfreaks.com/topic/162888-i-did-this-in-school/#findComment-859579 Share on other sites More sharing options...
.josh Posted June 19, 2009 Share Posted June 19, 2009 We're not talking about php, we're talking about basic math you learn in like 1st grade. Seriously, my 8 year old just finished 2nd grade. He brought home homework last year (1st grade) dealing with %'s. So hey OP, if you're like 8 years old, hats off to you bud. Quote Link to comment https://forums.phpfreaks.com/topic/162888-i-did-this-in-school/#findComment-859588 Share on other sites More sharing options...
dreamwest Posted June 20, 2009 Author Share Posted June 20, 2009 Dude what do they teach you kids in school these days? They obviously aren't teaching even basic math.. should just cut to the chase and teach you how to hold a spatula and flip a burger so you'll be prepared for your future career. What's really sad is that I'm not joking. I used to manage a fastfood joint and you'd be surprised at how many people failed at even doing stuff like that. I did maths B...and physics, was a b+ student. Sometimes i get writers block - programming style. Thats why u see me asking all the stupid questions - Im not stupod hunust Calm down for all you know he could be a youngster, in which case hes not doing bad having a go at PHP (though it does depend on age).... Check my profile to see how old i am.... Quote Link to comment https://forums.phpfreaks.com/topic/162888-i-did-this-in-school/#findComment-860027 Share on other sites More sharing options...
Ken2k7 Posted June 20, 2009 Share Posted June 20, 2009 Percentage is always portion divided by total. So if you have 5000 votes and 6 says yes, then 5000 is the total and 6 is the portion; ergo, (6/5000) * 100 to get the percentage. Quote Link to comment https://forums.phpfreaks.com/topic/162888-i-did-this-in-school/#findComment-860031 Share on other sites More sharing options...
MadTechie Posted June 20, 2009 Share Posted June 20, 2009 Ken2k7, do you read the posts in the thread or just the first one! Quote Link to comment https://forums.phpfreaks.com/topic/162888-i-did-this-in-school/#findComment-860163 Share on other sites More sharing options...
.josh Posted June 20, 2009 Share Posted June 20, 2009 Ken2k7, do you read the posts in the thread or just the first one! He's a very busy guy. He can't be bothered with details like reading past the first post. Also, if you live by the philosophy that you are right and everybody else is wrong (which a lot of people seem to), it's really a waste of time to read past the first post. So he's just being efficient here. You should applaud him. Quote Link to comment https://forums.phpfreaks.com/topic/162888-i-did-this-in-school/#findComment-860165 Share on other sites More sharing options...
shedokan Posted June 20, 2009 Share Posted June 20, 2009 I think a better way to do this is, gethow much 1 percent is and divide the number you want to know how much percents it is. like this: to get how much percents 7 is in 10: 10/100=0.1 7/0.1=70 so in php $percents = 7 / (10/100); I think that's a lot easier than your ways. Quote Link to comment https://forums.phpfreaks.com/topic/162888-i-did-this-in-school/#findComment-860170 Share on other sites More sharing options...
phant0m Posted June 20, 2009 Share Posted June 20, 2009 what about something like this function get_percentage($val1, $val2, $precision=0){ $total = $val1 + $val2; $result = array(); $result[] = round($val1 / $total * 100, $precision); $result[] = 100 - $result[0]; return $result; } get_percentage(2, 4, 2); would return an array: Array ( [0] => 33.33 [1] => 66.67 ) Quote Link to comment https://forums.phpfreaks.com/topic/162888-i-did-this-in-school/#findComment-860185 Share on other sites More sharing options...
.josh Posted June 20, 2009 Share Posted June 20, 2009 I think a better way to do this is, gethow much 1 percent is and divide the number you want to know how much percents it is. like this: to get how much percents 7 is in 10: 10/100=0.1 7/0.1=70 so in php $percents = 7 / (10/100); I think that's a lot easier than your ways. umm..so how is $percents = 7 / (10/100); any easier than $percents = (7 / 10) * 100; Quote Link to comment https://forums.phpfreaks.com/topic/162888-i-did-this-in-school/#findComment-860186 Share on other sites More sharing options...
.josh Posted June 20, 2009 Share Posted June 20, 2009 what about something like this function get_percentage($val1, $val2, $precision=0){ $total = $val1 + $val2; $result = array(); $result[] = round($val1 / $total * 100, $precision); $result[] = 100 - $result[0]; return $result; } get_percentage(2, 4, 2); would return an array: Array ( [0] => 33.33 [1] => 66.67 ) so what are going to do with that function if you want to know what % 13 out of 45 is? Quote Link to comment https://forums.phpfreaks.com/topic/162888-i-did-this-in-school/#findComment-860190 Share on other sites More sharing options...
phant0m Posted June 20, 2009 Share Posted June 20, 2009 bascially, it is an answer to this question: Ok if theres 10 ppl and 7 say yes and 3 say no - what percentage says yes Answer : 23% But what if theres 1230 ppl and 14 say yes and 1216 say no , what percentage says yes. This is what im after Quote Link to comment https://forums.phpfreaks.com/topic/162888-i-did-this-in-school/#findComment-860195 Share on other sites More sharing options...
shedokan Posted June 20, 2009 Share Posted June 20, 2009 I think a better way to do this is, gethow much 1 percent is and divide the number you want to know how much percents it is. like this: to get how much percents 7 is in 10: 10/100=0.1 7/0.1=70 so in php $percents = 7 / (10/100); I think that's a lot easier than your ways. umm..so how is $percents = 7 / (10/100); any easier than $percents = (7 / 10) * 100; actually your'e right, but I think it looks cleaner. Quote Link to comment https://forums.phpfreaks.com/topic/162888-i-did-this-in-school/#findComment-860224 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.