Round to Closest N

Published by Matt in

Create a function that takes two integers, num and n, and returns an integer which is divisible by n and is the closest to num. If there are two numbers equidistant from num and divisible by n, select the larger one.

Examples

roundNumber(33, 25) ➞ 25

roundNumber(46, 7) ➞ 49

roundNumber(133, 14) ➞ 140

Notes

n will always be a positive number.

Watch a quick demo on how Edabit works.