当前位置: 技术问答>java相关
怎样把 44,234,434 转换成 数字 44234434 ?? 就是说去掉逗号(寻求最简单的方法)
来源: 互联网 发布时间:2015-07-04
本文导语: 怎样把 44,234,434 转换成 数字 44234434 ??(寻求最简单的方法) | StringTokenizer st = new StringTokenizer("44,234,4", ",") String s = ""; while (st.hasMoreTokens()){ s += st.nextToken(); } if (s != "") Integer.pa...
怎样把 44,234,434 转换成 数字 44234434 ??(寻求最简单的方法)
|
StringTokenizer st = new StringTokenizer("44,234,4", ",")
String s = "";
while (st.hasMoreTokens()){
s += st.nextToken();
}
if (s != "")
Integer.parseInt(s);
String s = "";
while (st.hasMoreTokens()){
s += st.nextToken();
}
if (s != "")
Integer.parseInt(s);
|
import java.text.*;
public class TestDec
{
public static void main(String[] args)
{
DecimalFormat df = new DecimalFormat("#,###,###,###");
String s = "44,234,434";
Number num = null;
try
{
num = df.parse(s);
}
catch(Exception e){}
System.out.println(num.intValue());
}
}
public class TestDec
{
public static void main(String[] args)
{
DecimalFormat df = new DecimalFormat("#,###,###,###");
String s = "44,234,434";
Number num = null;
try
{
num = df.parse(s);
}
catch(Exception e){}
System.out.println(num.intValue());
}
}
|
import java.text.*;
public class Test {
public static void main(String[] args) {
NumberFormat nf=NumberFormat.getIntegerInstance();
String s="32,432,434";
try{
Number n=nf.parse(s);
System.out.println(n.intValue());
}catch(ParseException e){
}
}
}
public class Test {
public static void main(String[] args) {
NumberFormat nf=NumberFormat.getIntegerInstance();
String s="32,432,434";
try{
Number n=nf.parse(s);
System.out.println(n.intValue());
}catch(ParseException e){
}
}
}