Question by
Shuher · Aug 31, 2015 at 06:18 PM ·
javascriptvariables
compare variables JS
hello there :)
var a : float = System.Math.Round(1.23987, 2);
var b : float = System.Math.Round(1.241, 2);
if(a == b);
{
Debug.Log(a+" = "+b);
}
if(a != b);
{
Debug.Log(a+" != "+b);
}
in log i can see 1.24 = 1.24 and 1.24 != 1.24 at the same time. why is that?
Comment
Best Answer
Answer by Landern · Aug 31, 2015 at 06:21 PM
Because you have terminated the if statements with a Semi-colon which just leaves two blocks(the curly braces) and the debug statements. Remove the semi-colons on the end of the if statements.
var a : float = System.Math.Round(1.23987, 2);
var b : float = System.Math.Round(1.241, 2);
if(a == b)
{
Debug.Log(a+" = "+b);
}
if(a != b)
{
Debug.Log(a+" != "+b);
}
Your answer
