Johnny000
Johnny000

Reputation: 2104

JavaScript .floor number

I want to floor a number always in the same frame of 6 numbers

so if I would have i.e. a number between 7-13 I want to floor it to 6. If I would have number inbetween 14-20 I would like to floor it to 13, 21-27 to 20 etc etc. I there any possility to do this with floor()

Upvotes: 1

Views: 1413

Answers (1)

Amadan
Amadan

Reputation: 198324

function weirdFloor(n) {
  return Math.floor(n / 7) * 7 - 1;
}

Upvotes: 7

Related Questions