double b =5.1212; DecimalFormat decimalFormat = new DecimalFormat(".#"); double c =Double.parseDouble(decimalFormat.format(b)) ;