如何将DecimalFormat的字符串返还转换为数字?

showboat 2008-03-07 04:10:17
DecimalFormat nf = new DecimalFormat ("###,###,###,###,##0.00") ;
现在要将53,135.98转换为53135.98?
...全文
324 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
tt2451 2008-03-07
  • 打赏
  • 举报
回复
DecimalFormat nf = new DecimalFormat ("###,###,###,###,##0.00") ;
Number a = null;
try
{
a = nf.parse("53,135.98");
}
catch (ParseException e)
{
e.printStackTrace();
}
double b=a.doubleValue();
nihuajie05 2008-03-07
  • 打赏
  • 举报
回复
我查不到....
只好用StringTokenizer了...
nihuajie05 2008-03-07
  • 打赏
  • 举报
回复
public static void main(String[] agrs)
{
DecimalFormat nf = new DecimalFormat ("###,###,###,###,##0.00") ;
System.out.println(nf.format(123456.123));
double d = 0;
try{
String str=nf.format(123456.123);
String newstr="";
StringTokenizer st=new StringTokenizer (str,",");
while(st.hasMoreElements())
{
newstr=newstr+st.nextToken();
}
d=Double.parseDouble(newstr);
}catch(NumberFormatException e){System.out.println("nihuajie");}
System.out.println(d);
}

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧