%0.2f
이 올바르지 않습니다. 당신은 %.2f
를 사용해야합니다
예 :
System.out.printf("Age Depreciation Amount: %.2f\n", ageDepreciationAmount);
또는 ageDepreciationAmount
경우
가
String
가
System.out.printf("Age Depreciation Amount: %.2f\n", Double.parseDouble(ageDepreciationAmount));
가 BTW 우리가 보통의 printf 후
\n
를 추가 할 수 있으며,하지 전에.
출력 : 당신이 공백으로 출력을 채우려는 경우 66
이 전체 폭이며, 2
소수점 자릿수이고, 당신이 %66.2
을 사용하는 것이
Age Depreciation Amount: 10500.00
. 그러나 이는 숫자에만 적용됩니다.
double ageDepreciationAmount = 10500.000000000002;
double ageDepreciationAmount2 = 100500.000000000002;
String tmp = String.format("$%.2f", ageDepreciationAmount);
String tmp2 = String.format("$%.2f", ageDepreciationAmount2);
System.out.printf("Age Depreciation Amount: %20s\n", tmp);
System.out.printf("Age Depreciation Amount: %20s\n", tmp2);
출력 :이 프로그램에 올 때 나는 완전한 재앙을 오전 *
Age Depreciation Amount: $10500.00
Age Depreciation Amount: $100500.00
*의 xD – Maroun