Round to the Nearest

Published by Ruud Peter Boelens in

Create a function that takes two numbers as arguments and returns the first number rounded to the nearest number, or a multiple of that number.

Examples

roundNearest(17, 10) ➞ 20

roundNearest(36.3) ➞ 36

roundNearest(123, 5) ➞ 125

Notes

If no nearest number is given, round the number as you normally would (see example #2).

Watch a quick demo on how Edabit works.