As shown below:
public static String reThreeStr(String ss){ boolean result= ss.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$"); if(result&&ss!=null&&!"".equals(ss)){ Double sss=Double.valueOf(ss); String numStr=new java.text.DecimalFormat("0.000").format(sss); Double lsDou=Double.valueOf(numStr); ss=String.valueOf(lsDou); } return ss; } public static BigDecimal reThreeBig(BigDecimal ss){ String numStr=new java.text.DecimalFormat("0.000").format(ss); BigDecimal newNum=new BigDecimal(numStr); return newNum; } public static String delezero(String old){ boolean result= old.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$"); if(result&&old!=null&&!"".equals(old)){ String newStr=old; if(old.contains(".0")){ old=newStr.substring(0, old.length()-2); } return old; }else{ return old; } }
The above common method of data conversion (recommended) for java POI parsing Excel is all the content shared by the editor , I hope it can give you a reference, and I also hope that everyone will support the PHP Chinese website.
For more articles related to the data conversion public method of java POI parsing Excel, please pay attention to the PHP Chinese website!