方法1. 
小数点后全“0”时,删除小数点后的 0,其他不管(参数类型为字符串)
例:“12345.000”--> "12345"
    "12345.001"--> "12345.001"方法2.
 删除整数前面的'0'(参数类型为字符串)
例: “0.1” --〉 “0.1”
      “010”--〉 “10”
       “101”--〉 “101”
时间紧急,请兄弟们尽量给的详细点,谢了!

解决方案 »

  1.   

    String test="00021321321.003240000"
    double temp=Double.parseDouble(test);
    test=String.valueOf(temp);
      

  2.   

    String st = "60.001";
    double d = Double.parseDouble(st);
    st = String.valueOf(d);
    if (st.endsWith(".0")) {
        st = st.substring(0, st.length() - 2);
    }
      

  3.   

    或则:
    String test="0002132132sads1.00dfds3240000";
    test.repalce("^\b0+","");
    test.repalce("0+\b$","");
    jdk1.4以上版本
      

  4.   

    可以分别写两个方法:
    方法1. 
    public String changCode(String code)throws Exception{
    int length=code.length();  
    int leng=code.length();  
    int er=code.indexOf(".");
    for(int i=er;i<length;i++)
    {
         String code1 = code.substring(leng-1, leng);
         if("0".equals(code1)){code=code.substring(0,leng-1);leng--;}
         else{i=length;}
       }
       return code;
     } 
      

  5.   

    import java.io.*;
    import java.util.*;
    import java.util.regex.*;
     
    public class Test {
        public static void main(String[] args) throws IOException {
            Pattern p=Pattern.compile("0*([^0][\\d\\.]*[^0])[0]*");
            String s="123.120000";
            String t="0000120";
            Matcher m=p.matcher(s);
            m.find();
         s=m.group(1);    
         System.out.println(s);
        
         m=p.matcher(t);
         m.find();
         t=m.group(1);
         System.out.println(t);
        }
    }
      

  6.   

    import java.io.*;
    import java.util.*;
    import java.util.regex.*;
     
    public class Test {
        public static void main(String[] args) throws IOException {
            Pattern p=Pattern.compile("0*([^0][\\d\\.]*[^0])[0]*");
            String s="123.120000";
            String t="0000120";
            Matcher m=p.matcher(s);
            m.find();
         s=m.group(1);    
         System.out.println(s);
        
         m=p.matcher(t);
         m.find();
         t=m.group(1);
         System.out.println(t);
        }
    }---------------OK
      

  7.   

    Pattern p = Pattern.compile("0*([^0][\\d]*[\\.]?[^0])[0]*");
      

  8.   

    String ss="0002132132sads1.00dfds3240000";
     ss=ss.replaceAll("^0+"," ");
     ss=ss.replaceAll("0+$"," ");
     ss=ss.trim();
    ----------------
    结果: ss="2132132sads1.00dfds324"
      

  9.   

    /*
     * Created on 2005-5-19
     *
     * TODO To change the template for this generated file go to
     * Window - Preferences - Java - Code Style - Code Templates
     *//**
     * <p>
     * Title: 
     * </p>
     * <p>
     * Description:
     * </p>
     * <p>
     * Copyright: Copyright (c) 2005
     * </p>
     * <p>
     * Company: 
     * </p>
     * 
     * @author flower.bee
     * @version data: 2005-5-19 time: 14:20:16
     */
    public class Delete {
    boolean needReset = false; public String init(String str) {
    for (int i = 0; i < str.length(); i++) {
    if (str.charAt(i) == '.')
    needReset = true;
    }
    String tmp = "";
    tmp = delete(str);
    if (needReset) {
    tmp = reset(tmp);
    tmp = delete(tmp);
    tmp = reset(tmp);
    }
    System.out.println(tmp);
    if (tmp.length() == 1 && tmp.equals("."))
    return "0";
    if (tmp.charAt(0) == '.')
    return "0" + tmp;
    if (tmp.charAt(tmp.length() - 1) == '.')
    return tmp + "0";
    return tmp; } private String delete(String str) {
    int seek = 0;
    if (str.length() < 1 || str.equals(null))
    return str;
    if (str.charAt(1) == '.')
    return str;
    for (int i = 0; i < str.length(); i++) {
    if (str.charAt(i) == '0')
    seek++;
    else
    break;
    }
    return str.substring(seek, str.length());
    } private String reset(String str) {
    String tmp = "";
    for (int i = str.length() - 1; i >= 0; i--) {
    tmp += str.charAt(i);
    }
    return tmp;
    } public static void main(String[] args) {
    Delete d = new Delete();
    System.out.println(d.init("0110.0110")); }
    }
      

  10.   

    强制类型转换,转换成int型~~~
      

  11.   

    今天有空,写两个方法可以实现楼主的要求:
    方法1:小数点后全“0”时,删除小数点后的 0,其他不管(参数类型为字符串)
    public String changCode1(String code)throws Exception{
    int length=code.length();
    int leng=code.length();
    int er=code.indexOf(".");
    for(int i=er;i<length;i++)
    {
         String code1 = code.substring(leng-1, leng);
         if("0".equals(code1)){code=code.substring(0,leng-1);leng--;}
         else{i=length;}
       }
       int leng1=code.length();
       if(leng1==leng){code=code.substring(0,leng1-1);}
       return code;
     }方法2:删除整数前面的'0'(参数类型为字符串) public String changCode2(String code)throws Exception{
     int length=code.length();
     int er=code.indexOf(".");
     if(er<1){er=length;}
      String code1="";
      int j=0;
     for(int i=0;i<er-1;i++)
     {
     code1=code.substring(i,i+1);
     if("0".equals(code1)){
        j++;
     }
     else{i=er-1;}
     }
     code=code.substring(j,length);
     return code;
     }
      

  12.   

    强制类型转换,转换成int型~~~
    -----------------------------------
    强制转换可能会越界,开始我也这么想
    我的目的是把小数点后第三位开始全部截掉(不四舍五入)
    不知大家还有没有更好的办法?分不够另开贴
      

  13.   

    回复人: jihanzhong(逍遥) ( ) 信誉:100  2005-05-19 15:15:00  得分: 0  
     
     
       恩~我写的那个有什么不适用的地方吗?
    已经够简单的了
      
     
    ----------------------------------------------
    我说的是一个新问题
    把double型数值的小数点两位以后截掉
      

  14.   

    for(count = 0; count < len; count++){
          if(intchr[count] != 0){
            break;
          }
        }
        intnumber = new int[len - count];
        for(int i = count; i < len; i++){
          intnumber[i - count] = intchr[i];
        }
    这是除去前面的零的方法。
    这是别人帮我做的,我也不是很懂,你做个参考吧
      

  15.   

    ----------------------------------------------
    我说的是一个新问题
    把double型数值的小数点两位以后截掉-------------
    用NumberFormat