Python 官方文档:入门教程 => 点击学习
我就废话不多说了,大家还是看代码吧 String s="0000000002121210" s=s.replaceAll("^(0+)", ""); System.out.pri
String s="0000000002121210"
s=s.replaceAll("^(0+)", "");
System.out.println(s);
补充:Java中数字处理去掉末尾的0
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
利用“########.##########”
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。如有错误或未考虑完全的地方,望不吝赐教。
--结束END--
本文标题: Java 如何使用正则表达式去除前导0
本文链接: https://www.lsjlt.com/news/123717.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0