两个Integer 的量相除,结果想要保留一位小数点的float,
请问该怎么做啊!

解决方案 »

  1.   


    DecimalFormat df=new DecimalFormat("0.0");
    Integer a=3, b=2;
    System.out.println(df.format(a/b));
      

  2.   


    public static String formatFloat(float f){
     java.text.DecimalFormat format = (java.text.DecimalFormat)java.text.DecimalFormat.getInstance();
      format.applyPattern("####.#");
      return format.format(f);
    }
      

  3.   

    int i=7;
    int j=3;
    float result =(float)i/j;
    System.out.println(Math.round(result*10)/10.0);//或System.out.println(Math.round(result*10)/10f);
      

  4.   

    package com.question;import java.text.DecimalFormat;public class Q4 {
        public void compute() {
            Integer i = 2630;
            Integer j = 1000;
            DecimalFormat df = new DecimalFormat("0.0");
            String s = df.format((float)i/j);
            System.out.println(s);
        }
        
        public static void main(String[] args) {
            Q4 q4 = new Q4();
            q4.compute();
        }
    }