Moving to far

I have a problem where I try to move a object in a direction and it should stop when it has reached a certain value.

So for example the objects position is 1 and the value it should become is 2 and I increase the value of one by 0.001. And then I tell the object to stop when the first value is no longer lower then the secon value. But what happens is that I end up with 2.00001 does anybody has a idea how to fix this?

void SwipingMovement()
{
	bool stillSwiping = false;
	float moveSpeed = 0.01f;
	for(int i = 0; i < playPieceList.Count; i++)
	{
		for(int ii = 0; ii < 7; ii++)
		{
			if(playPieceList_[ii].playPiece.transform.position != playPieceList*[ii].newPos)*_

* {*
* stillSwiping = true;*
if(playPieceList_[ii].playPiece.transform.position.x < playPieceList*[ii].newPos.x)
{
playPieceList[ii].playPiece.transform.position += new Vector3(moveSpeed, 0, 0);
}
}
}
}
if(!stillSwiping)
{
actionState = “Neutral”;
}
}*_

Unfortunately, due to floating point errors and the Polling nature of observing figures this will always be a problem.

Your best bet is simply to Clamp the value.

A simple idea of this is…

if(value > 2)
    value = 2;