zahid zubair wrote:Hmmm. I got this setRoundingMode method. However, I am required to write this logic in Java 1.4 version, but I could find this method newly added only from version Java 1.6. Is there any other alternative for it?
That stinks. Why are you stuck with Java 1.4? It has been at End of Life for some time? Shouldn't you think about updating to a supported version of Java?
Anyway, in Java 1.4 DecimalFormat always rounded towards the even number for xxx5. So if it was 2.015 it would round to 2.02 and if it was 2.025 it would round to 2.02 which I think is used because it more evenly disperses rounded values. the only way I know how to make sure it always makes half-values round up would be to use BigDecimal and set the scale.
Something like: