import java.text.DecimalFormat;
import java.text.NumberFormat;public class NumFormat 
{ public static void main(String args[]) 
{
System.out.println(percent(0.2341));
}
public static String percent(double dblNum)
{
NumberFormat ft = new DecimalFormat("#,##0.00");
return ft.format(dblNum*100)+"%";
}
}

解决方案 »

  1.   

    int x=2;
    int y=3;
    int f = 2;//小数点后要保留位数int a = x*100/y;
    int b = ((x*100%y)*pow(10,f))/y;
    int c = ((x*100%y)*pow(10,f))%y;
    if(c>=5) b +=1;String str = a+"."+b+"%";最后str就是你要的形式了
      

  2.   

    “四舍五入”有点问题
    改成
    int c = (((x*100%y)*pow(10,f))%y)/y;顺便:用float类型比较好
      

  3.   

    DecimalFormat df = new DecimalFormat();
    double a=2d/3d;
    df.applyPattern("#.00%");
    df.format(a);
    System.out.println(df.format(a));
      

  4.   

    特别是自JDK1.4.1版本发布以后,对数据格式化的东西就更方便了,有很多种实现方法
      

  5.   

    多谢各位了!!!
    liaoqingpeng(棋快一步) 和 thinkerhj(布恩特) 介绍的方法很好用,不错!
    micromai(micromai) 的就繁一点点。
    :)
      

  6.   

    关于double的四舍五入有问题,勉强用了 顶 thinkerhj(布恩特)
      

  7.   

    总结了一下,liaoqingpeng(棋快一步) 和 thinkerhj(布恩特)的方法是大同小异的:
    DecimalFormat df=new DecimalFormat("#0.00%");
    double a=2d/3d;
    System.out.println(df.format(a));