470,849 Members | 1,074 Online

# percentages in PHP

I am wanting to write a function for a poker league manager that will
detrmine players finishing points in a tournament depending on the amount of
players that played... In other words when the tournament director enters
the tournament results into the database, he will enter the number of
players that played and then upon submissin this funtion will takek that
number and if it is in certain ranges will then know which payout structure
to use... for example...

If the total players were 25, then it would determine that for this amount
of players only the top 10 places will get points, and then will use a pre
determined "chart" of percentages and then calculate the players points..

i.e the charts or database would be something like.. and there would have to
be diffrent tables for each players registered range

PLAYER RANGE = 1-10
RANK | PAYOUT PERCENTAGE
========================================
1 | 70%
2 | 20%
3 | 10%
etc etc
Now I have a basic idea of how to get this function to do the majority of
what i need, except I do not know how to make it calculate the points from
percentages and (also all final points have to be rounded up/down)

in other words what is the correct format for this type of equation.

\$prize_pool = "5000";
\$total_points = 70% of \$prize_pool
Also any other suggestions you may have id be glad to hear.
Apr 5 '06 #1
5 1724 Chris H schrieb:
[...]
in other words what is the correct format for this type of equation.

\$prize_pool = "5000";
\$total_points = 70% of \$prize_pool

I'm not sure if I understood your problem.

<?
\$total_points = (int) \$prize_pool * 0.7;
// if needed
\$total_points = round(\$total_points);
?>

Can it be that simple?

Michael
Apr 5 '06 #2
i knew it was something simple liek that, damm brain farts... for some
reason my basic math skills escaped me and i forgot how to convert the %
into a usable number by php.. i.e using decimal places... i didnt know about
the round() function though, yet another one of the many functions i have
yet to come across..

"Michael Pichler" <ma**@michaelpichler.de> wrote in message
news:e1*************@news.t-online.com...
Chris H schrieb:
[...]
in other words what is the correct format for this type of equation.

\$prize_pool = "5000";
\$total_points = 70% of \$prize_pool

I'm not sure if I understood your problem.

<?
\$total_points = (int) \$prize_pool * 0.7;
// if needed
\$total_points = round(\$total_points);
?>

Can it be that simple?

Michael

Apr 5 '06 #3
What does (int) do? I recognize it as something to do with "integer". but im
not sure what exactly the purpose is of the (int) is

<?
\$total_points = (int) \$prize_pool * 0.7;
// if needed
\$total_points = round(\$total_points);
?>
"Michael Pichler" <ma**@michaelpichler.de> wrote in message
news:e1*************@news.t-online.com...
Chris H schrieb:
[...]
in other words what is the correct format for this type of equation.

\$prize_pool = "5000";
\$total_points = 70% of \$prize_pool

I'm not sure if I understood your problem.

<?
\$total_points = (int) \$prize_pool * 0.7;
// if needed
\$total_points = round(\$total_points);
?>

Can it be that simple?

Michael

Apr 5 '06 #4
Message-ID: <bUUYf.878243\$x96.643349@attbi_s72> from Chris H contained
the following:
What does (int) do? I recognize it as something to do with "integer". but im
not sure what exactly the purpose is of the (int) is

http://uk2.php.net/manual/en/languag...es.typecasting

That said, I don't really know why it's there. The result of dividing
something by 0.7 is quite likely to be something other than an integer.

There is even a warning about it
http://uk2.php.net/manual/en/languag...nteger.casting
--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
Apr 5 '06 #5
Chris H wrote:
"Michael Pichler" <ma**@michaelpichler.de> wrote in message
news:e1*************@news.t-online.com...
Chris H schrieb:
[...]
in other words what is the correct format for this type of
equation.

\$prize_pool = "5000";
\$total_points = 70% of \$prize_pool

I'm not sure if I understood your problem.

<?
\$total_points = (int) \$prize_pool * 0.7;
// if needed
\$total_points = round(\$total_points);
?>

Can it be that simple?

What does (int) do? I recognize it as something to do with "integer".
but im not sure what exactly the purpose is of the (int) is

<?
\$total_points = (int) \$prize_pool * 0.7;
// if needed
\$total_points = round(\$total_points);
?>

It converts the resulting float to an integer:
http://php.net/language.types.intege...nteger.casting

--
Kim André Akerø
 reply views Thread by Avinash Dhoot | last post: by reply views Thread by michael | last post: by 1 post views Thread by Megan | last post: by 2 posts views Thread by Dot net work | last post: by 26 posts views Thread by Mike Barnard | last post: by 1 post views Thread by Bob Alston | last post: by 9 posts views Thread by AZKing | last post: by 3 posts views Thread by martin DH | last post: by reply views Thread by marcopolo8 | last post: by reply views Thread by ryjfgjl | last post: by reply views Thread by AlexandraMT | last post: by reply views Thread by prepawan | last post: by 1 post views Thread by DANILIN | last post: by reply views Thread by tracyyun | last post: by reply views Thread by sjain6 | last post: by reply views Thread by jackhack | last post: by reply views Thread by Ravipg | last post: by reply views Thread by zachatmarco | last post: by