Java 字符串浮点数前后去多余的零

Java 字符串浮点数前后去多余的零

public String MoveZero(String s){
    BigDecimal bigDecimal = new BigDecimal(s);//去掉前面多余的零
    String result = bigDecimal.toString();
    if(result.indexOf(".")>0){
        result = result.replaceAll("0+?$","");//去掉后面无用的零
        result = result.replaceAll("[.]$","");//如小数点后面全是零去掉小数点
    }
}

你可能感兴趣的:(java)