Monday Morning Maths

Okay so it’s monday (Thursday, but whatever) morning and my brain isnt firing completely.

There’s not a simpler way to perform the following line, is there?
$x -= $x % $y;
(“Floor $x to the nearest whole value when divided by $y”)

1 Like
$x = intdiv($x, $y);

See da manual

The RFC also proposed the %% operator for this, but it seems that didn’t make it.

Mmh… no… integer division of 17/4 would return 4. I want 16. I’ve probably stated the original post poorly.

For a given X and Y; find the greatest value of N such that N*Y <= X. Return N*Y.

Hm… So $x = $y * intdiv($x, $y), though I don’t think that’s better than what you already had …

It’s entirely possible. I didnt THINK there was something like a %% or other operand that would return it, but never hurts to ask.

1 Like