NumberUtils新增formatNumber方法

This commit is contained in:
thinkgem
2018-08-29 23:34:28 +08:00
parent 27434ee26e
commit 5706c8bfc9
2 changed files with 23 additions and 0 deletions

View File

@@ -4,6 +4,7 @@
package com.jeesite.common.lang;
import java.math.BigDecimal;
import java.text.DecimalFormat;
/**
* BigDecimal工具类
@@ -92,4 +93,19 @@ public class NumberUtils extends org.apache.commons.lang3.math.NumberUtils {
return bg.setScale(0, BigDecimal.ROUND_HALF_UP).toString();
}
/**
* 格式化数值类型
* @param data
* @param pattern
*/
public static String formatNumber(Object data, String pattern) {
DecimalFormat df = null;
if (pattern == null) {
df = new DecimalFormat();
} else {
df = new DecimalFormat(pattern);
}
return df.format(data);
}
}