Share on Google+Share on Google+

Formatting and Parsing Locale-Specific Currency

In this section, you will learn how to format and parse the locale specific currency.

Formatting and Parsing Locale-Specific Currency

In this section, you will learn how to format and parse the locale specific currency.

Through the formatting, you can translate the binary data into user-readable textual representation of the values. This is not a difficult task. By providing Formatters like, NumberFormat, Decimal format etc, Java has made programming easier. Here we are going to format the number into locale specific currency using NumberFormat class. This class is a locale sensitive which format the primitive type numbers into a locate specific string.

In the given example, we have specified a locale 'FRANCE' and invoked getCurrencyInstance() method to create a formatter. This method returns a string with the formatted number and the appropriate currency sign and the method format() formats the number. For parsing, we have used parse() method which parse the text to produce a number.

Here is the code:

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

public class FormattingAndParsingUsingLocaleSpecificCurrency {
	public static void main(String[] args) {
		Locale locale = Locale.FRANCE;
		String st = NumberFormat.getCurrencyInstance(locale).format(123.45);
		try {
			Number number = NumberFormat.getCurrencyInstance(locale).parse(st);
		} catch (Exception e) {



123,45 ?


Posted on: October 11, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.