提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
将双值格式设置为货币
/*nowjava - 时 代 Java 提供*/ import java.text.NumberFormat; public class Main { public static void main(String[] args) { NumberFormat cf = NumberFormat.getCurrencyInstance(); double myAllowance = 5.00; cf = NumberFormat.getCurrencyInstance(); System.out.println("My allowance: " + cf.format(myAllowance)); double costOfPaintBallGun = 12.34; cf = NumberFormat.getCurrencyInstance(); System.out.println("Cost of Paint Ball Gun: " + cf.format(costOfPaintBallGun)); } }