avatar Bite 289. Round to next number

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.  

Login and get coding
go back Beginner level
Bitecoin 2X

24 out of 25 users completed this Bite.
Will you be Pythonista #25 to crack this Bite?
Resolution time: ~20 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 1.67 on a 1-10 difficulty scale.
» You can do it! 😌

We use Python 3.8