I have a double (23.46)
And using the methods Math.ceil and Math.floor and parsing my double to these methods, I get the same value returned to me, which is 23...
Unable to reproduce:
public class Test
{
public static void main(String[] args)
{
System.out.println(Math.ceil(23.46)); // Prints 24
System.out.println(Math.floor(23.46)); // Prints 23
}
}
I suspect that either you haven't got the input data you think you have or you're not writing out the output data you think you are. Math.floor
/ceil
themselves work fine. The only time they will return the same value is when the input is already an integer. You talk about parsing your double... my guess is that the error lies there. Please show us a short but complete program which demonstrates the problem.
(There may be other scenarios around very large values where the exact target integer can't be represented exactly as a double
- I haven't checked - but that's certainly not the case here.)