Created
November 5, 2014 01:46
-
-
Save jimbray/5c5faad771ccb63b6474 to your computer and use it in GitHub Desktop.
金额格式化
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 金额格式化 | |
* @param s 金额 | |
* @param len 小数位数 | |
* @return 格式后的金额 | |
*/ | |
public static String FormatCurrency(String s, int len) { | |
if (s == null || s.length() < 1) { | |
return "0.00"; | |
} | |
NumberFormat formater = null; | |
double num = Double.parseDouble(s); | |
StringBuffer buff = new StringBuffer(); | |
if (len == 0) { | |
formater = new DecimalFormat("###,###"); | |
} else { | |
buff.append("###,###."); | |
for (int i = 0; i < len; i++) { | |
buff.append("#"); | |
} | |
formater = new DecimalFormat(buff.toString()); | |
} | |
formater.setMinimumFractionDigits(len);//设置最小存在的小数点后位数 | |
return formater.format(num).toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment