プログラムでJavaのNumberFormatクラスとgetPercentInstanceメソッドを使用して税金を計算しようとしています。プログラムに表示させたいのは、小数点以下2桁のパーセンテージです。さて、以前に小数をパーセントでフォーマットしようとすると、Javaは0.0625のようなものを6%として表示しました。Javaにそのような小数を表示させる、または0.0625を「6.25%」と言うにはどうすればよいですか?
コードフラグメント:
NumberFormat fmt1 = NumberFormat.getCurrencyInstance();
NumberFormat fmt2 = NumberFormat.getPercentInstance();
System.out.print("Enter the quantity of items to be purchased: ");
quantity = scan.nextInt();
System.out.print("Enter the unit price: ");
unitPrice = scan.nextDouble();
subtotal = quantity * unitPrice;
final double TAX_RATE = .0625;
tax = subtotal * TAX_RATE;
totalCost = subtotal + tax;
System.out.println("Subtotal: " + fmt1.format(subtotal));
System.out.println("Tax: " + fmt1.format(tax) + " at " + fmt2.format(TAX_RATE));
System.out.println("Total: " + fmt1.format(totalCost));