如何设置双精度格式以仅显示两位小数?

时间:2019-07-29 11:28:51

标签: java formatting

我只希望显示2个小数点println不起作用,或者我错了。

我尝试使用println,但不起作用

    double p=1000;
    double r= 0.05;
    int n;
    double a;
    System.out.println("Year \tAmount of Money");
    for( n=1; n<=10; n++){

        double exp = Math.pow((1+r),n);
        a = p*exp;
        System.out.println(n+"\t"+a);

我希望“ a”的输出仅显示两位小数。

0 个答案:

没有答案