import java.text.DecimalFormat;
public static void main(String[] args) {
DecimalFormat dataFormat = new DecimalFormat( "0.0");
double a=12.345;
float b=67.890f;
System.out.println(a);
System.out.println(b);
System.out.println("***********************");
a = Double.parseDouble(dataFormat.format(a));
b = Float.parseFloat(dataFormat.format(b));
System.out.println(a);
System.out.println(b);
}
结果:
12.345
67.89
***********************
12.3
67.9