That is expected, the translation from Euler angles to Quaternion and back is not lossless - rounding errors cause slight variation of the results, and also the Euler angles are normalized into a specific set of ranges which can lead to sharp changes in value (e.g. 360 => 0).
You can either add some leeway to your "if", or test like this instead:
if (targetRotation == angle)
{
...
}
which should work for your case. It would not necessarily work, though, for Y axis rotations, nor for certain key angles about any axis, due to the sharp jumps in Euler angle values at those points.
↧