Round to the Nearest Value

March 4, 2010Danwize No Comments »

As I was developing a game I needed something to round an integer to the nearest 5. The following function allows you to round a given integer n to the nearest integer f. It’s a very simple Actionscript function, but I it might come in handy.

public function round(n:int, f:int):int
     return Math.round(n/f)*f;

Tags: , , ,

Join the discussion