Incorrect Division and Remainder

Hello,

I am using the following code and looking at the results in the inspector at runtime:

var number = 0.0;
var quotient = 0.0;
var remainder = 0.0;

function Update () {

	quotient = Mathf.Floor(number / 12);
	remainder  = number % 12;

}

It should divide the varable ‘number’ by 12 giving the ‘quotient’ rounded down to the nearest whole number, and the ‘remainder’.

But, if I set ‘number’ to equal 12.99, the remainder given is 0.9899998, instead of 0.99.

Can anyone see where i am going wrong?

Any help is appreciated.

Hi, I guess this is a float precision issue. Here is a good article about it here: http://www.gamasutra.com/view/feature/1965/visualizing_floats.php?print=1

In your case, your may be able to increase precision using: remainder = number - (quotient * 12). You could also try using double precision float, it has the same behavior as regular floats but with greater accuracy.

you can´t divide 0
I think that this is the error.