Java-小数点控制
package 运算及类型转换类;import java.text.DecimalFormat;
public class 控制小数点类 {
public static double decimalFormatD(int num, double d){
String format = "0.";
String result = "";
double db;
for(int i=0;i<num;i++)
format = format.concat("0");
DecimalFormat decimal = new DecimalFormat(format);
result = decimal.format(d);
db = Double.parseDouble(result);
return db;
}
public static float decimalFormatF(int num, float f){
String format = "0.";
String result = "";
float fl;
for(int i=0;i<num;i++)
format = format.concat("0");
DecimalFormat decimal = new DecimalFormat(format);
result = decimal.format(f);
fl = Float.parseFloat(result);
return fl;
}
public static String doubleToString(double f){
String s = "";
double a = 0;
while(f >= 1) {
a = f%((double)10);
s = String.valueOf((int)a) + s;
f=(f - a)/10;
}
return s;
}
}
以上是 Java-小数点控制 的全部内容, 来源链接: utcz.com/z/392097.html