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…
I want it to be rounded off to 24.. In otherwords, if I have a double that’s 15.01, it should still be rounded off to 16… How do I do this?
Unable to reproduce:
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/ceilthemselves 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.)