集册 Java实例教程 将双精度格式设置为货币

将双精度格式设置为货币

—— 将双值格式设置为货币

欢马劈雪     最近更新时间:2020-01-02 10:19:05

558
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
将双值格式设置为货币
/*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));

  }


}