percentages in PHP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris H

    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.


  • Michael Pichler

    #2
    Re: percentages in PHP

    Chris H schrieb:
    [...][color=blue]
    > in other words what is the correct format for this type of equation.
    >
    > $prize_pool = "5000";
    > $total_points = 70% of $prize_pool
    >[/color]

    I'm not sure if I understood your problem.

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

    Can it be that simple?

    Michael


    Comment

    • Chris H

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

      Anyway.. thanks michael for your quick reply


      "Michael Pichler" <mail@michaelpi chler.de> wrote in message
      news:e102a4$pci $01$1@news.t-online.com...[color=blue]
      > Chris H schrieb:
      > [...][color=green]
      >> in other words what is the correct format for this type of equation.
      >>
      >> $prize_pool = "5000";
      >> $total_points = 70% of $prize_pool
      >>[/color]
      >
      > I'm not sure if I understood your problem.
      >
      > <?
      > $total_points = (int) $prize_pool * 0.7;
      > // if needed
      > $total_points = round($total_po ints);
      > ?>
      >
      > Can it be that simple?
      >
      > Michael
      >
      >[/color]


      Comment

      • Chris H

        #4
        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_po ints);
        ?>


        "Michael Pichler" <mail@michaelpi chler.de> wrote in message
        news:e102a4$pci $01$1@news.t-online.com...[color=blue]
        > Chris H schrieb:
        > [...][color=green]
        >> in other words what is the correct format for this type of equation.
        >>
        >> $prize_pool = "5000";
        >> $total_points = 70% of $prize_pool
        >>[/color]
        >
        > I'm not sure if I understood your problem.
        >
        > <?
        > $total_points = (int) $prize_pool * 0.7;
        > // if needed
        > $total_points = round($total_po ints);
        > ?>
        >
        > Can it be that simple?
        >
        > Michael
        >
        >[/color]


        Comment

        • Geoff Berrow

          #5
          Re: percentages in PHP

          Message-ID: <bUUYf.878243$x 96.643349@attbi _s72> from Chris H contained
          the following:
          [color=blue]
          >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[/color]



          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

          --
          Geoff Berrow 011000100110110 0010000000110
          001101101011011 001000110111101 100111001011
          100110001101101 111001011100111 010101101011

          Comment

          • Kim André Akerø

            #6
            Re: percentages in PHP

            Chris H wrote:
            [color=blue]
            > "Michael Pichler" <mail@michaelpi chler.de> wrote in message
            > news:e102a4$pci $01$1@news.t-online.com...[color=green]
            > > Chris H schrieb:
            > > [...][color=darkred]
            > > > in other words what is the correct format for this type of
            > > > equation.
            > > >
            > > > $prize_pool = "5000";
            > > > $total_points = 70% of $prize_pool[/color]
            > >
            > > I'm not sure if I understood your problem.
            > >
            > > <?
            > > $total_points = (int) $prize_pool * 0.7;
            > > // if needed
            > > $total_points = round($total_po ints);
            > > ?>
            > >
            > > Can it be that simple?
            > >[/color]
            > 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_po ints);
            > ?>[/color]

            It converts the resulting float to an integer:


            --
            Kim André Akerø
            - kimandre@NOSPAM betadome.com
            (remove NOSPAM to contact me directly)

            Comment

            Working...