Couldn't figure out why must i need to RoundToInt before compare

The following is from the immediate window, I paused the program and evaluate the value.

Basically i need to compare the ‘x’ coordinate, i always use RoundToInt when i do any rotation or movement so their x y z coordinate must be an integer. I just dont understand why goEach.transform.position.x == 1 returns false.

? goEach.transform.position.x
1
? goEach.transform.position.x == 1
false
? goEach.transform.position.x == 1.0f
false
? goEach.transform.position.x - 1
0
? goEach.transform.position.x - 1 == 0
true
? goEach.transform.position.x == 1
false
? Mathf.RoundToInt(goEach.transform.position.x) == 1
true

Long story short:
You should not rely on float comparisons as they’re not accurate and will fail quite often.
Mathf.RoundToInt(…) returns an integer. Integers can be compared using ‘==’ as there is nothing like imprecision.
If you still want to compare float values, consider using Mathf.Approximately for that.

Thanks, u saved my wall.