How to get 360 angle in y axis

Hello,
I am experiencing rotation of gameObject.
When the mouse is over it - I want it to rotate 180 degree and when it`s out I want it to rotate back and so on.
The problem is that I can do only 1 spin - after the first one it doesnt work.
my code:

private void OnMouseOver()
    {
      
        exit = false;
        if (card_Play.transform.rotation.eulerAngles.y < 180 && card_Play.transform.rotation.eulerAngles.y >= 0)
            card_Play.transform.Rotate(0, rotation_spd, 0);
        if (card_Play.transform.rotation.eulerAngles.y == 90)
            card_Play.GetComponent<SpriteRenderer>().sprite = card_Play_Sprite;
    }

    private void OnMouseExit() { exit = true; }

    // Update is called once per frame
    void Update () {
        Debug.Log(card_Play.transform.rotation.eulerAngles.y);
        if (exit)
        {
            if (card_Play.transform.rotation.eulerAngles.y >= 180 && card_Play.transform.rotation.eulerAngles.y < 360)
                card_Play.transform.Rotate(0, rotation_spd, 0);
            if (card_Play.transform.rotation.eulerAngles.y == 270)
                card_Play.GetComponent<SpriteRenderer>().sprite = card_Blank;
        }
    }

When the object completes the rotation, instead of 360, the console shows me this:
-8.996128E-06

The value ‘-8.996128E-06’ is very nearly 0. That’s scientific notation for ‘-0.000008996128’. And it’s because rotating actually modifies the quaternion and slight float error creeps in every time you do so.

Furthermore, testing if ‘y’ is some value is a bad idea. Since really the rotation is stored as a complex quaternion, rather than its euler angles. Accessing ‘eulerAngles’ just converts the quaternion to a vector. This conversion does not take into consideration what the previous rotation was. Just the current rotation. And well… 0 and 360 are equal!

Also, note this:

card_Play.transform.rotation.eulerAngles.y == 90

NEVER do direct == comparison of a float. Especially a comparison of a float that has gone through some sort of conversion (like as the member of a quaternion to the member of a euler angle vector).

Float error can creep in, and you seldom will have an ‘exact’ value.

This is why things like ‘Mathf.Approximately’ exist: