I don't think Math.round()
has implementation which supports long
argument. Here is the Math.round()
signature.
Math.round(double a);
Math.round(float a);
Math.round()
accepts double
or float
, So when you are passing long
you are doing something like (long
converts to float implicitly)
float x = 1423562400L;
System.out.println(Math.round(x));
To Solve this you can add your long
value to double
first and it will work like charm.
double x = 1423562400L;
System.out.println(Math.round(x));
To simplify you can do
Math.round((double)1423562400L)
or
Math.round(1423562400d)
Here is the picture that shows the how implicit conversion works and why long
gets converted to float

Image source here