3.字符串保留2位小数?(代码)

public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        double pi = 3.14159265358979323;
        double area = r * r * pi;
        // "%.6f" 其中 .6 代表小数后面保留6位,f 代表小数
        String str = String.format("%.6f", area);
        System.out.println(str);
    }

 

原文地址:https://www.cnblogs.com/cjeandailynotes/p/10855602.html