rounding rotation to nearest 90 degrees

I know how I could do this with a lot of if statements and loops, but I was wondering if there's an elegant way to round the three axis' of a rotation to the nearest (0, 90, 180, 270, 360)?

For example, round Vector3(86.9385, 0, 180) to (90, 0, 180) or (90, 272.345, 178.83) to (90, 270, 180)

This should do it, but be careful - changing euler angles this way is a pretty easy way to have randomly flipping objects:

var vec = transform.eulerAngles;
vec.x = Mathf.Round(vec.x / 90) * 90;
vec.y = Mathf.Round(vec.y / 90) * 90;
vec.z = Mathf.Round(vec.z / 90) * 90;
transform.eulerAngles = vec;

If you want to smoothly round the rotations (like snapping to a view), you can use Mathf.LerpAngle which works like Lerp, but "makes sure the values interpolate correctly when they wrap around 360 degrees".

This and Mike's rounding the euler angles will probably do the trick.