Is it possible to turn the robot to a certain degree with Compass?

Hey Guys,

I have followed Johns approach, the problem is: the compass has inaccuracy and it does not give exactly 45 degree. for example, if the desire angle is 45 degrees, it turns the robot but does not stop because the compass has 1 or 2 degrees inaccuracy.

if(error == 0){ somecode; }

Error never become 0, since 45 becomes 46 or 47. what I am trying to do is define a range, between 45 and 50, if the compass reading is between 45 and 50 it should stop.