Conversion trouble between int and float in Javascript

New to Javascript. I’m sure it’s something obvious, but the following code is driving me batty:

var x:int = (1.3 * 10.0) - 10.0;
var y:float = 1.3;
var z:int = (y * 10.0) - 10.0;
Debug.Log("x is " + x);
Debug.Log("z is " + z);

Outputs

x is 3
z is 2

Anyone know why? What’s the right way to use a variable in this scenario? I also tried parseInt().

In dealing with floating point numbers, your 1.3 might be represented as 1.2999999999999, so in calculating ‘z’, you would get 2.9999999999999 which is converted to 2 as an integer. You can solve this by using Mathf.RoundToInt().

var z:int = Mathf.RoundToInt((y * 10.0) - 10.0);