Format double value as currency - Java Language Basics

Java examples for Language Basics:double

Description

Format double value as currency

Demo Code

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));
  }/*w  w w  .  j a  v a 2s  .c o m*/

}

Related Tutorials