- Home /
Question by
zoono · Mar 03, 2015 at 01:36 PM ·
javascriptscripting problemfunction
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
Comment
Answer by tanoshimi · Mar 03, 2015 at 01:36 PM
Because floating point maths is inherently imprecise. http://en.wikipedia.org/wiki/Floating_point
Your answer
![](https://koobas.hobune.stream/wayback/20220613184847im_/https://answers.unity.com/themes/thub/images/avi.jpg)