Problem with SUM

I wrote a simple code , but its output is not true:


using UnityEngine;  
using System.Collections;  

public class Camera01 : MonoBehaviour   
{
	private float Temp1 = .1f;
	private float Temp2 = .01f;
	
	void LateUpdate () 
	{
		Temp1 += Temp2;
		print (Temp1);
	}
}

And output is something like this:


0.11 → 0.120001 → . → . → . → 1.999998 → . → . → and etc.

Why?
Thanks

1 Answer

1

Because floating point maths is inherently imprecise. Floating-point arithmetic - Wikipedia