Jump to content

I did this in school..


dreamwest

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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).... :P

Link to comment
Share on other sites

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).... :P

 

Check my profile to see how old i am....

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
)

Link to comment
Share on other sites

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;

 

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.