There are already so many questions asked about this already.
One popular answer is to use the below formula.
Math.ceiling(myValue * 20) / 20
I need the following output for corresponding input.
16.489 (input) - 16.49(output)
Using the above formula
16.489*20 = 329.78
Math.ceil(329.78) = 330.0
and 330.0 /20 = 16.5
but what I want is 16.49.
Ideally the Math.ceil stuff should have given 329.8
So how do we get around the above case? There are many other cases similar to this.
Instead of multiplying / dividing with 2*10, you should do it with 102.
However, I suggest you use
Math.round(100*a) / 100.0, or if you need it for printing,printforDecimalFormat.Examples:
Output: