标签:
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; } }
标签:
原文地址:http://www.cnblogs.com/hwaggLee/p/4510659.html