By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,050 Members | 1,148 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,050 IT Pros & Developers. It's quick & easy.

percentages in PHP

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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..

Anyway.. thanks michael for your quick reply
"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

P: n/a
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

P: n/a
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

P: n/a
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ĝ
- ki******@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)
Apr 6 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.