-1

I have such a problem, I want to round the given numbers to the nearest high number that is divisible by 5. For example:

let num = 12;
function round5(arg) {
    console.log(Math.round(arg / 5) * 5)
}

round5(num)

In this case, I want the result to be 15. What would be the best solution for this? Thanks in advance.

Nightcrawler
  • 943
  • 1
  • 11
  • 32

2 Answers2

1

round will round to the closest integer so 2.4 becomes 2. You want to use ceil which always round up so 2.4 becomes 3

let num = 12;
function round5(arg) {
    console.log(Math.ceil(arg / 5) * 5)
}

round5(num)
litelite
  • 2,857
  • 4
  • 23
  • 33
1

you should use Math.ceil which will round up

function round5(arg) {
    console.log(Math.ceil(arg / 5) * 5)
}
Liad
  • 789
  • 4
  • 10