java中保留几位小数?


public class NumUtils {
/**
* 保留两位小数
*
* @param d
* @return
*/
public static String get2Wei(double d) {
java.text.DecimalFormat df = new java.text.DecimalFormat("#.##");
return df.format(d);
}
/**
* 保留两位小数
*
* @param d
* @return
*/
public static String get2Wei(Float d) {
if (d == null)
return "0";
java.text.DecimalFormat df = new java.text.DecimalFormat("#.##");
return df.format(d);
}
/**
* 保留0位小数
*
* @param d
* @return
*/
public static String get0Wei(double d) {
java.text.DecimalFormat df = new java.text.DecimalFormat("#");
return df.format(d);
}
/**
* 保留0位小数
*
* @param d
* @return
*/
public static String get0Wei(Float d) {
if (d == null)
return "0";
java.text.DecimalFormat df = new java.text.DecimalFormat("#");
return df.format(d);
}
}