Home Tutorials I18N Currency Format Example



Currency Format Example
Posted on: September 13, 2008 at 12:00 AM
This Example shows you how to format currency according to the locale. In the code given below we are formatting Currency according to the locale.

Currency Format Example

     

This Example shows you how to format currency according to the locale. In the code given below we are formatting Currency according to the locale.

Methods used in this example are described below :

NumberFormat.getCurrencyInstance : NumberFormat class provides the functionality for formatting and parsing currency. NumberFormat class also provides methods for defining which locales have currency formats.

NumberFormat.format() : This method returns a format string of a currency.

CurrencyFormatExample.java


import java.text.*;
import java.util.*;

class CurrencyFormatExample {
  public void currencyFormat(Locale currentLocale) {
   Double currency = new Double(9843.21);
   NumberFormat currencyFormatter;
 String currencyOut;
   currencyFormatter = NumberFormat.getCurrencyInstance(currentLocale);
 currencyOut = currencyFormatter.format(currency);
 System.out.println(currencyOut + " " + currentLocale.toString());
  }

  public static void main(String args[]) {
 Locale[] locales = new Locale[]{new Locale("fr""FR"),
   
new Locale("de""DE"), new Locale("ca""CA"),
   new 
Locale
("rs""RS"),new Locale("en""IN")
  };

   CurrencyFormatExample[] formate =
    
new CurrencyFormatExample[locales.length];

  for (int i = 0; i < locales.length; i++) {
  formate[i].currencyFormat(locales[i]);
  }
  }
}

Output :
9Â 843,21 â?¬ fr_FR

9.843,21 â?¬ de_DE

CAD 9.843,21 ca_CA

RSD 9,843.21 rs_RS

Rs.9,843.21 en_IN

Download code

     

Related Tags for Currency Format Example:
cormformattingformformatlocalecurrencythislocalshowforexampletoexamwssheinrmcalmcalochowxaxampsatisivmplarcodcodeccttssrdrenthshobelopleplodeo


More Tutorials from this section

Ask Questions?    Discuss: Currency Format Example   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.