我有二个int  int x = 500   int y =600
我要求出它们的百分比 要 显示成 83.33%在线等哈~~

解决方案 »

  1.   

    是不是要先把int转成double之类的再来除啊,但这种变量类型间的转换不会哈? 有这方面的资源的朋友也请提供一下哈!!!
      

  2.   

    可二个int除出来还是个int.  请帮我写一下吧。
      

  3.   

    就像你说的 用long接着 不行就转了再除
      

  4.   

    int m = 500 * 10000;
    int n = 600;
    System.out.println(new Float(m / n) / 100 + "%");
      

  5.   

    <%
      java.text.DecimalFormat ad = new java.text.DecimalFormat("0.00");
      int x = 500;
        int y = 600;
        double x1 = (double)x;
        double y1 = (double)y;
        double z = 0;
        z = x1/y1;
        double z1 = z*100; %>
        <%=ad.format(z1)+"%" %>
      

  6.   

    public class Test {
    public void getText(){
    int x=500;
    int y=600;
    double z = x/(y*1.0);
    System.out.println(java.text.DecimalFormat.getInstance().format(z*100)+"%");
    }
    public static void main(String[] args) {
    new Test().getText();
    }
    }
      

  7.   


    import java.text.DecimalFormat;
    public class Test {
    public static void main(String args[]) {
    int x=500;
    int y=600;
    double result=Double.parseDouble(String.valueOf(x))/Double.parseDouble(String.valueOf(y));
    DecimalFormat df=new DecimalFormat("##.00%");
    System.out.println(df.format(result));
    }}
      

  8.   

            DecimalFormat df=new DecimalFormat("#.00%");
            System.out.println(df.format(x*1.0/y));
      

  9.   

    非常感谢大家。 这题里我是需要 这个的 double x1 = (double)x
    这就是int转double哈~ 再次感谢!!
      

  10.   

    我者也有个方法,希望有用
             int i=500;
            int y=600;
            double num=(double)i*100/y;
            DecimalFormat format=new  DecimalFormat();
            format.setMaximumFractionDigits(2);
            String temp=format.format(num)+"%";
            System.out.println("=="+temp);
      

  11.   

    支持11楼的办法,要设定格式,将int转double哈. 
      

  12.   

    NumberFormat format = NumberFormat.getPercentInstance();
    format.setMaximumFractionDigits(2);
    System.out.println(format.format(500.0/600));
      

  13.   


    java.text.NumberFormat nfp = java.text.NumberFormat.getPercentInstance();
    nfp.setMaximumFractionDigits(2);
    System.out.println(nfp.format(x*1.0 / y));
      

  14.   

    Dim i As Integer = 500
            Dim j As Integer = 600
            Dim a As String        a = CStr((i / j) * 100)
            a = a.Substring(0, 5) & "%"
            MsgBox(a)
      

  15.   

    好啊。
    CSDN升级了啊。回复的字少就、也不行了啊