任何人都可以帮我删除输出中的逗号吗?

时间:2016-02-19 05:46:03

标签: java

所以我的代码定期正确地输出复合兴趣,但它是用逗号输出我的输出。例如:$ 1,000.00我想答案是:$ 1000.00。

这是我的代码人员:

package certificatedeposit;

public class CertificateDeposit {

    public static void main(String[] args) {

        double PV = 1000.00;

         System.out.printf("Enter annual rate: ");
          java.util.Scanner in = new java.util.Scanner( System.in );
            double rate = in.nextDouble( );
              double rates = rate / 100 / 12; 

         System.out.printf("Enter CD term in months: ");
            int months = in.nextInt( );

        double product = ( 1 + rates);
        double exp = Math.pow(product,months);
        double fv = PV * exp;

        System.out.printf("An initial investment of $1000.00 after "+months+" months at annual rate of %,.2f%% is $%,.2f \n", rate, fv);                    
    }
}

2 个答案:

答案 0 :(得分:0)

我已经为你更改了代码,但正如@ajb在评论中说的那样,你得到了","因为您在格式化字符串时使用了它。深入理解阅读here

package certificatedeposit;

public class CertificateDeposit {

    public static void main(String[] args) {

        double PV = 1000.00;

         System.out.printf("Enter annual rate: ");
          java.util.Scanner in = new java.util.Scanner( System.in );
            double rate = in.nextDouble( );
              double rates = rate / 100 / 12; 

         System.out.printf("Enter CD term in months: ");
            int months = in.nextInt( );

        double product = ( 1 + rates);
        double exp = Math.pow(product,months);
        double fv = PV * exp;

   System.out.printf("An initial investment of $1000.00 after "+months+" months at annual rate of %,.2f%% is $%.2f \n", rate, fv);

    }

}

答案 1 :(得分:0)

从变量fv的格式字符串中删除逗号:

System.out.printf("An initial investment of $1000.00 after "+months+" months at annual rate of %,.2f%% is $%.2f \n", rate, fv);

同样here是关于使用不同(不仅是逗号)符号进行分组分隔符的讨论。