public class DoubleTrans{
public static String doubleTrans(double d){
if(Math.round(d)-d==0){
return String.valueOf((long)d);
}
return String.valueOf(d);
}
public static void main(String args[]){
double a=3.0d,b=3.1d;
System.out.println(doubleTrans(a));
System.out.println(doubleTrans(b));
}
}
運(yùn)行結(jié)果:
3
3.1