Question

How to make a function so that make floor all the number as times of 18?

example:

3 => 0

17 => 0

19 => 18

43 => 36

69 => 54

Thanks.

Was it helpful?

Solution

$a = 19;
$a -= $a % 18; // => 18

OTHER TIPS

By using Modulus operator (%)

 $a % $b = gives the remainder of $a divided by $b.

In your case,

 $a = 3;
 $a = $a - ($a % 18);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top