Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use regular expressions to remove 0 from a string in Java

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to use regular expressions to remove zeros in strings in Java". In daily operations, I believe many people have doubts about how to use regular expressions to remove zeros in strings in Java. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to use regular expressions to remove zeros in strings in Java". Next, please follow the editor to study!

I'll cut the crap. Let's take a look at the code String s = "0000000002121210" s=s.replaceAll ("^ (0 +)", "); System.out.println (s).

Add: remove the last 0 from the digital processing in Java

Examples are as follows: 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; iTunes +) {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

Make use of "#."

At this point, the study on "how to use regular expressions to remove zeros from strings in Java" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report