1. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jan 2017
Posts
99
Rep Power
2

#### Number function !?

Is there any function that will display a number as 60+ if the result its equal to 60 or higher but lower than 65 and if its egual to 65 or higher but lower than 70 to display 65+ ?
I'm not talking about this number in particular, but in general for all numbers. I would like to count my article views like this not like 60,61,62,63 .... 70 x viewed.
Like an interval from 5 to 5 and so on.
2. No, there's nothing built in for that. You'll have to write one. Perhaps something like this:

Code:
```function bucketize(\$num, \$size){
\$overage = \$num % \$size;
\$base = \$num - \$overage;

return \$base . '+';
}```
https://3v4l.org/fk35k

The % operator does integer division between the two numbers and returns the remainder of that operation. You can use that to determine how far past your base number you've gone and then calculate that base number to show.
3. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jan 2017
Posts
99
Rep Power
2
And how to integrate this? I'm kinda lost. My view variable is \$row["times_viewed"]
4. It's a function. Look at the code, understand how it works at a basic level, then put the function into your application and call it with the right arguments.
5. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jan 2017
Posts
99
Rep Power
2
It gives me "missing argument 2" notification
6. Then you need to call the function with the second argument.

Or perhaps you should start first with a tutorial on how to use PHP?
7. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Apr 2016
Location
Cheshire, UK
Posts
90
Rep Power
72
The method I use to round up or down to the nearest N (in your case N is 5) is

PHP Code:
``` floor(\$num/\$N)*\$N;     // to round down ceil(\$num/\$N)*\$N;      // to round up  ```
So my function would be
PHP Code:
```    function nearestN(\$num, \$N, \$roundup=false)    {        return \$roundup ? ceil(\$num/\$N)*\$N : floor(\$num/\$N)*\$N;    }     echo nearestN(68, 5);             //-> 65     echo nearestN(68, 5, 1);          //-> 70  ```
8. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jan 2017
Posts
99
Rep Power
2
Originally Posted by requinix
Then you need to call the function with the second argument.

Or perhaps you should start first with a tutorial on how to use PHP?