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
Post a Comment