NumberFormat格式化输出——数值格式化
示例
保留c位小数 int a = in.nextInt(); int b = in.nextInt(); int c = in.nextInt(); NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMinimumFractionDigits(c); String s = nf.format((double)a/b); System.out.println(s);
NumberFormat格式化输出——数值格式化
示例
保留c位小数 int a = in.nextInt(); int b = in.nextInt(); int c = in.nextInt(); NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMinimumFractionDigits(c); String s = nf.format((double)a/b); System.out.println(s);