DecimalFormat my_nf = new DecimalFormat("##0.##"); jtxt_rate.setText(String.valueOf(my_nf.format(rs.getInt(1)*100/(float)rs.getInt(3)))+"%");

解决方案 »

  1.   

    package test;import java.text.DecimalFormat;public class TestDecimalFormat {
        private static DecimalFormat df = new DecimalFormat("##0.0000");
        public static String numberToString(double d){
            String s = df.format(d);
            System.out.println(s);
            return s;
        }
        public static void main(String[] args){
            numberToString(1);
            numberToString(1.23);
            numberToString(1.23456);
        }
    }结果:
    1.0000
    1.2300
    1.2346