Kata of the Day #22

Round up to the next multiple of 5

kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
Kata of the Day #22

Given an integer as input, can you round it to the next (meaning, "greater than or equal") multiple of 5?

TypeScript


function roundToNext5(n: number): number {
  return n + (5 - n) % 5;
}

console.log(roundToNext5(100));

Go


package main

import "fmt"

func roundToNext5(n int) int {
  return n + (5 - n % 5) % 5
}

func main() {
  fmt.Println(roundToNext5(100))
}

Python


def round_to_next_5(n):
    return n + (5 - n) % 5

print(round_to_next_5(100))

PHP


function roundToNext5($n) {
  return $n + (5 - $n % 5) % 5;
}

echo roundToNext5(100);

Go to Kata
ByCesar Kohl

Need some help?

Want us to give you some help with your business? No problem, here's a video on who we can help, and how, along with our calendar so you can book in a call to discuss us working together.

Let's see
budget
budget
budget
budget
budget
budget
budget
budget
budget
budget

Subscribe to our newsletter

subscribe
subscribe
subscribe
subscribe
subscribe
subscribe
subscribe
subscribe
subscribe
subscribe