- import java.util.Scanner;
- public class FloorDemo {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double d = scanner.nextDouble();
- scanner.close();
- String string = String.valueOf(d);
- int index = string.indexOf('.');
- String subString = string.substring(0, index + 3);
- int x = Integer.parseInt(string.substring(index + 3, index + 4));
- System.out.println(Double.parseDouble(subString));
- }
- }
复制代码 思路是:讲double转变成String,然后取有效位,再把String转换成double |