Author Topic: Points for playing  (Read 1216 times)

wilwer

  • Newbie
  • *
  • Posts: 4
    • View Profile
Points for playing
« on: December 15, 2012, 08:50:38 AM »
Hello I use the following formula to calculate the points.
(positioning * 2) + if (r <= ceil (N * .2), (​​ceil (N * .2) + 1 - r) * 7, 0) (position * 2) + if (r <= ceil (n * .2), (ceil (n * .2) + 1 - r) * 7, 0) + if (r> 1.0, n/100 * 25)
Now he counted all the points correctly except for the first player, the points put behind comma (eg 415.5) instead of 415
This is somewhere in this line + if (r> 1.0, n/100 * 25) where I would have to lend to the code ceil. Where do these come. Can someone help me.

Corey Cooper

  • Administrator
  • Hero Member
  • *****
  • Posts: 6216
    • View Profile
Re: Points for playing
« Reply #1 on: December 15, 2012, 10:05:41 AM »
If you just want to make sure it ends up with a whole number (not a fraction), use round(), floor() or ceil(), to round to the nearest, round down, or round up, respectively.  For example:

round((positioning * 2) + if (r <= ceil (N * .2), (​​ceil (N * .2) + 1 - r) * 7, 0) (position * 2) + if (r <= ceil (n * .2), (ceil (n * .2) + 1 - r) * 7, 0) + if (r> 1.0, n/100 * 25))

Your formula has a couple of other issues.  "positioning" is not a valid variable; it should just be "position".  Also, there seems to be a missing "+" (might be some other operator, but + seems logical, I guess):

(position * 2) + if (r <= ceil (N * .2), (ceil (N * .2) + 1 - r) * 7, 0) + (position * 2) + if (r <= ceil (n * .2), (ceil (n * .2) + 1 - r) * 7, 0) + if (r> 1.0, n/100 * 25)
                                                                         ^
                                                                         here


Also, there's a Unicode character in there called "a zero width space".  Being "zero width", it's actually basically invisible, but it's there and it causes the formula to error.  It's right between the open parenthesis and the "c" in "ceil", here:

(position * 2) + if (r <= ceil (N * .2), (ceil (N * .2) + 1 - r) * 7, 0) + (position * 2) + if (r <= ceil (n * .2), (ceil (n * .2) + 1 - r) * 7, 0) + if (r> 1.0, n/100 * 25)
                                         ^^
                                         here


Here's your original formula with the + added and the "zero width space" removed:

(position * 2) + if (r <= ceil (N * .2), (ceil (N * .2) + 1 - r) * 7, 0) + (position * 2) + if (r <= ceil (n * .2), (ceil (n * .2) + 1 - r) * 7, 0) + if (r> 1.0, n/100 * 25)

If you want to round everything:

round((position * 2) + if (r <= ceil (N * .2), (ceil (N * .2) + 1 - r) * 7, 0) + (position * 2) + if (r <= ceil (n * .2), (ceil (n * .2) + 1 - r) * 7, 0) + if (r> 1.0, n/100 * 25))

wilwer

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Points for playing
« Reply #2 on: December 15, 2012, 01:03:44 PM »
 :) Thank you very much Corey. It works perfect now.

Corey Cooper

  • Administrator
  • Hero Member
  • *****
  • Posts: 6216
    • View Profile
Re: Points for playing
« Reply #3 on: December 15, 2012, 08:39:08 PM »
Glad to help.    :)