Funny bug in Java
import java.math.*;
public class Test{
public static void main(String args[]){
Double a = new Double(0.865);
System.out.println("The Rounded price a is "+roundOff1(a));
}
public static Double roundOff1(Double finalDiscountedPrice){
BigDecimal roundfinalDiscPrice =
new BigDecimal(finalDiscountedPrice.doubleValue()).setScale(2,BigDecimal.ROUND_HALF_UP);
Double finalDiscPrice= new Double(roundfinalDiscPrice.doubleValue());
return finalDiscPrice;
}
}
I was trying to roundOff to a scale of 2. Ideal the above code should convert .865 to .87 but it doesnot.
it does convert for most of the number but for some it doesnt like .725 and .825. It will leave them as .72 and .83. But .625 and .925 will be converted to .63 and .93
Can any bdy suggest me what could be the problem or any other API to so this.
Thanks

