public class Formatutils {
//千分位
public static String fmtMicrometer(String text) {
DecimalFormat df = null;
if (text.indexOf(".") > 0) {
if (text.length() - text.indexOf(".") - 1 == 0) {
df = new DecimalFormat("###,##0.00");//0.00
} else if (text.length() - text.indexOf(".") - 1 == 1) {
df = new DecimalFormat("###,##0.00");//0.00
} else {
df = new DecimalFormat("###,##0.00");//0.00
}
} else {
df = new DecimalFormat("###,##0.00");//0.00 ###,##0
}
double number = 0.00;
try {
number = Double.parseDouble(text);
} catch (Exception e) {
number = 0.00;
}
return df.format(number);
}
//去除小数后面无用的零
public static String removeTrim(String barValue) {
if (TextUtils.isEmpty(barValue)) return "";
if (barValue.indexOf(".") > 0) {//正则表达
barValue = barValue.replaceAll("0+?$", "");//去掉后面无用的零
barValue = barValue.replaceAll("[.]$", "");//如小数点后面全是零则去掉小数点
}
return barValue;
}
}
千分位显示
最新推荐文章于 2023-01-06 21:30:00 发布