percentages in PHP

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
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.

Re: percentages in PHP

Chris H schrieb:
[...]

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

Re: percentages in PHP

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..

Re: percentages in PHP

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);
?>

Re: percentages in PHP

the following:

http://uk2.php.net/manual/en/language.types.type-juggling.php#language.types.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/language.types.integer.php#language.types.integer.casting
--
Geoff Berrow  0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011

Re: percentages in PHP

Chris H wrote:

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

--
Kim André Akerø