Hi,
I want to display the first three numbers after a point of a float value.
Example:
float 61.001 => 1
I have done this (using c#):
float value = 61.001;
float temp = (value*1000);
int retVal = ((int)temp)%1000;
retVal has value 1 → This is correct
but when I am not using the temp var:
float value = 61.001;
int retVal = ((int)(value*1000))%1000;
retVal has value 0, what is not correct.
I really wonder why those two calculations return different values.
In my three or four tests done, the second implementation seems to return 1 less than the other. (ie. 58 instead of 59)
This cant be caused by float rounding, can it?
Is there a optimization that causes this difference?
Thanks!