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);
}
}

相关文章:

  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
  • 2021-09-20
猜你喜欢
  • 2022-12-23
  • 2022-02-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2020-03-30
  • 2022-12-23
相关资源
相似解决方案