这是我的代码:
System.out.printf("\n%-10s%9s%11s%13s%9s\n",
"yearBuilt","area(sqf)","price","replaceRoof","sqfPrice");
System.out.printf("\n%-10d%9.1f$%11.2f%13s$%8.2f\n",
house1.getYear(),house1.getSquareFeet(),house1.getPrice(),house1.isRoofChangeNeeded(),house1.calcPricePerSqf());
这是我得到的输出结果:
yearBuilt area(sqf) price replaceRoof sqfPrice
1996 2395.0$ 195000.00 true$ 81.42
这是我想要的输出结果:
yearBuilt area(sqf) price replaceRoof sqfPrice
1996 2395.0 $195000.00 true $81.42
我尝试使用DecimalFormat,但在printf内部使用时似乎无法正常工作,而在程序的其他区域正常工作。有没有什么方法可以解决这个问题?
NumberFormat
的预定义格式。 - adamdc78