java - Math.round gives a decimal number in android -


i have fuction:

enemigo.posz = 5.1529696e8 //this value @ runtime, it's float. double posicionz = math.round(enemigo.posz*100.0f)/100.0f; 

and output, why? should round integer!

posicionz = 2.1474836e7 

an integer lot of digits begins 21474... should clue!

java has 2 versions of math.round():

public static int math.round(float a)    // float  -> 32-bit int public static long math.round(double a)  // double -> 64-bit long 

let's @ code:

double posicionz = math.round(enemigo.posz * 100.0f) / 100.0f; 

since enemigo.posz float, first version used. wants return enemigo.posz * 100.0, or 51529696000.0, 32-bit int, can't because overflows. returns integer.max_value, or 2^³¹ - 1 = 2147483647. divison 100.0f returns 21474836.0, 2.1474836e7.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

python - RuntimeWarning: PyOS_InputHook is not available for interactive use of PyGTK -