/**
* 将数字格式化为decimalSize位小数
*
* @param number
* @param decimalSize
* @return
* StringUtils是Tomcat下面的包的内容
*/
public static String formatNumber(String number, int decimalSize) {
String result = "";
if (StringUtils.isNotBlank(number)) {
String formatStr = "###";
String formatEndStr = ".";
if (decimalSize < 0) {
decimalSize = 0;
}
for (int i = 0; i < decimalSize; i++) {
formatEndStr += "0";
}
if (!".".equals(formatEndStr)) {
formatStr += formatEndStr;
}
DecimalFormat df = new DecimalFormat(formatStr);
try {
result = df.format(Double.valueOf(number));
if (result.startsWith(".")) {
result = "0" + result;
}
} catch (NumberFormatException e) {
result = "0";
e.printStackTrace();
}
}
return result;
}
* 将数字格式化为decimalSize位小数
*
* @param number
* @param decimalSize
* @return
* StringUtils是Tomcat下面的包的内容
*/
public static String formatNumber(String number, int decimalSize) {
String result = "";
if (StringUtils.isNotBlank(number)) {
String formatStr = "###";
String formatEndStr = ".";
if (decimalSize < 0) {
decimalSize = 0;
}
for (int i = 0; i < decimalSize; i++) {
formatEndStr += "0";
}
if (!".".equals(formatEndStr)) {
formatStr += formatEndStr;
}
DecimalFormat df = new DecimalFormat(formatStr);
try {
result = df.format(Double.valueOf(number));
if (result.startsWith(".")) {
result = "0" + result;
}
} catch (NumberFormatException e) {
result = "0";
e.printStackTrace();
}
}
return result;
}