Java examples for Language Basics:double
Format double value as currency
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*/ }