public class Test13_3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);//创建键盘录入对象
System.out.println("请输入一个Double类型的数");
double d = sc.nextDouble();
double d2 = keep2Decimals(d);
System.out.println(d2);
}
private static double keep2Decimals(double d) {
int a = (int)(d*100); //如2.3456-->234
double b = a; //234.0
double c = b/100; //2.34
return c;
}
}
这是我自己的方法,老师看了也觉得很简单,希望采纳 |