两个整数相除,结果保留一位小数点,怎么做。。。 两个Integer 的量相除,结果想要保留一位小数点的float,请问该怎么做啊! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 DecimalFormat df=new DecimalFormat("0.0");Integer a=3, b=2;System.out.println(df.format(a/b)); public static String formatFloat(float f){ java.text.DecimalFormat format = (java.text.DecimalFormat)java.text.DecimalFormat.getInstance(); format.applyPattern("####.#"); return format.format(f); } 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); 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(); }} java基础问题!!!!!! 关于scanner控制台输入输出问题 今天面试题 有点迷糊??? 请教关于多线程的问题 Java中日期的检错问题 怎样改textfield的大小 为什么我用dispose()关闭了当前窗口,但在控制台中看到程序还在继续运行? java的字符处理方法如何处理带有括号的字符串 帮忙看一下 why 为什么基本数据类型的范围正数绝对值比负数绝对值小1 请教各位大虾:linux下怎么用java调c急!!!!!!!
DecimalFormat df=new DecimalFormat("0.0");
Integer a=3, b=2;
System.out.println(df.format(a/b));
public static String formatFloat(float f){
java.text.DecimalFormat format = (java.text.DecimalFormat)java.text.DecimalFormat.getInstance();
format.applyPattern("####.#");
return format.format(f);
}
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);
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();
}
}