方式一:
例如:”0000123” (字符串必须全为数字)
处理过程:
String tempStr = "0000123";
int result = Integer.parseInt(tempStr);
result 结果:123
方式二:
例如:”0000123”
处理过程:
String str = "0000123";
String newStr = str.replaceFirst("^0*", "");
System.out.println(newStr);
打印结果:123
方式三:
例如:”0000123”
String str = "0000123";
String newStr = str.replaceAll("^(0+)", "");
System.out.println(newStr);
处理过程:打印结果:123
再加一种:
public class MainActivity extends AppCompatActivity { TextView tv; String num = "0001234560"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv = (TextView) findViewById(R.id.tv); tv.setText( getData(num)); /** * num.charAt(0);//第一位数 * num.charAt(num.length()-1);//最后一位数 */ } private String getData(String num) { num.trim();//获得对象的字段值,然后转成String类型 ,并且去掉前后空白(去掉两边空格) String number = "0"; for (int i = 0; i < num.length(); i++) { if (num.charAt(i)>48&&num.charAt(i)<58){ Log.d("MainActivity", num.substring(i, num.length())); String a = num.substring(i, i + 1); if (a.charAt(0)>48){ number = num.substring(i, num.length()-2)+"."+num.substring(num.length()-2); break; } }if (i== s.length()-3 && s.charAt(s.length()-3) == 48){ number = s.substring(i,s.length()-2)+"."+s.substring(s.length()-2); break; }} return number; }}
tv显示为:00012345.60
如果num = "0000000"
那么tv显示为0.00
小菜鸟学习ing~~~