double d = 1234567.01;
DecimalFormat df = new DecimalFormat("#,###,###.##");
String str1 = df.format(d);
System.out.println(str1);这样可以吗?
DecimalFormat df = new DecimalFormat("#,###,###.##");
String str1 = df.format(d);
System.out.println(str1);这样可以吗?
String format(String s)
{
int index=s.lastIndexOf(".");
if(index<0) index=s.length();
for(int i=index;i>3;i-=3)
{
s=s.substring(0,i-3)+","+s.substring(i-3,s.length());
}
return s;
}
import java.util.Locale;
public class DD {
public static void main(String args[]) {
double d=1234567.01;
// 得到本地的缺省格式
NumberFormat nf1 = NumberFormat.getInstance();
System.out.println(nf1.format(d));
}
}
这个怎么样啊,你想得到别国的形式都可以NumberFormat.getInstance();
如果想试试手,可以自己写一个方法,实现,用while吧,我用c写过