Pybites Logo

Round to next number

Level: Beginner (score: 2)

Write a function that accepts a number and a multiple, then rounds the number towards the next multiple.

Examples:  

Number Multiple Output
0 5 0
2 5 5
5 5 5
42 5 45
-6 -10 -10
-6 -10 -10

---

Imagine this on a number line.  

* Number: 0 Multiple: 5  

-3 -2 -1 0 1 2 3 4 5
      0          
      0          

 

Since zero is a multiple of five the answer is 0.  

---

* Number: 2 Multiple: 5  

-5 -4 -3 -2 -1 0 1 2 3 4 5
              2      
              =>     5

 

The next multiple of five from two is 5.

---

* Number: -6 Multiple: -10  

-10 -9 -8 -7 -6 -5 -4 -3 -2 -1
        -6          
-10       <=          

 

The next multiple of negative 10 from negative six is -10.