亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Java 如何使用正則表達(dá)式去除前導(dǎo)0

 更新時(shí)間:2021年04月16日 08:37:27   作者:吹牛大王歷險(xiǎn)記  
這篇文章主要介紹了Java 使用正則表達(dá)式去除前導(dǎo)0的操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧

我就廢話不多說了,大家還是看代碼吧

String s="0000000002121210"
s=s.replaceAll("^(0+)", "");
System.out.println(s);

補(bǔ)充:Java中數(shù)字處理去掉末尾的0

實(shí)例如下所示:

public static String insertComma(String s, int len) {
    if (s == null || s.length() < 1) {
        return "";
    }
    NumberFormat formater = null;
    double num = Double.parseDouble(s);
    if (len == 0) {
        formater = new DecimalFormat("###,###");
 
    } else {
        StringBuffer buff = new StringBuffer();
        buff.append("###,###.");
        for (int i = 0; i < len; i++) {
            buff.append("#");
        }
        formater = new DecimalFormat(buff.toString());
    }
    return formater.format(num);
}
double num = 5.5500; 
DecimalFormat decimalFormat = new DecimalFormat("##########.##########"); 
String numConverted = decimalFormat.format(num); //5.55

利用“########.##########”

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。

相關(guān)文章

最新評論