- Home /
value float approximately equal to float
I have 1 value for example 3.39945
How can test if value approximately equal to 4.4?
And test if vector3(14,3.39945,0) approximately equal to vector3(14,4.4,0) or not.
Comment
Best Answer
Wiki
Answer by jite · May 27, 2012 at 07:59 AM
//C#
static bool RoughlyEqual(float a, float b) {
float treshold = 2f; //how much roughly
return (Math.Abs(a-b)< treshold);
}
and about vectors comparison: http://answers.unity3d.com/questions/131624/vector3-comparison.html
Answer by loihb · May 27, 2012 at 08:19 AM
Thanks!!!
Working fine, if value approximately equal to +0.02,-0.02 = 1 then valu = true.
var valuee : float;
var valu : boolean;
function Update() {
valu = Mathf.Abs(valuee-1) < 0.02;
}
Your answer
