Rounding off number to the nearest multiple of 10

how do I round off a given number to the nearest multiple of 10 in elixir

It’s probably like rounding the tenth of the value… and multiply by 10.

1 Like
round_ten = fn(n) -> round(n / 10) * 10 end
2 Likes

Well, you didn’t specified the rounding method, so I assume that any will do:

def round10(n) when rem(n, 10) < 6, do: n - rem(n, 10)
def round10(n), do: n + (10 - rem(n, 10))
4 Likes

Thanks a lot, it has worked