Home >Java >javaTutorial >Common methods for data conversion in java POI parsing Excel

Common methods for data conversion in java POI parsing Excel

高洛峰
高洛峰Original
2017-01-24 13:45:191677browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn