Possible Duplicate:
How to round a number to n decimal places in Java
I am having a Double value like "1234.9678" . i want to return only with one decimal without rounding or ceiling.
I have used this way but its returning "1234.96"
public double roundTwoDecimals(double d) {
DecimalFormat twoDForm = new DecimalFormat("#.##");
return Double.valueOf(twoDForm.format(d)); }
I want only "1234.9",
I have even used this way... But no luck... Can anyone help?
double d = 1234.9678;
int decimalPlace = 1;
BigDecimal bd = new BigDecimal( Double.toString(d) );
bd = bd.setScale( decimalPlace, BigDecimal.ROUND_HALF_UP );
System.out.println( bd.doubleValue() );