How do I format a number for a locale?

Category: java.text, viewed: 5341 time(s).
package org.kodejava.example.text;

import java.util.Locale;
import java.text.NumberFormat;

public class LocaleNumberFormat {

    public static void main(String[] args)  {

        //
        // Format number for Italy locale. In Italy locale the decimal point
        // symbol is a comma.
        //
        NumberFormat formatter = NumberFormat.getNumberInstance(Locale.ITALY);
        try {
            String number = formatter.format(195325.75);
            System.out.println("Number in Italy: " + number);
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }

        //
        // Format number for Japan locale. In Japan locale the decimal point
        // symbol is a dot.
        //
        formatter = NumberFormat.getNumberInstance(Locale.JAPAN);
        try {
            String number = formatter.format(195325.75);
            System.out.println("Number in Japan: " + number);
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
    }
}
Click here to lend your support to: Kode Java Org and make a donation at www.pledgie.com !

 

Can't find what you are looking for? Join our FORUMS and ask some questions!
Download Hundreds of Complimentary Industry Resources

Get hundreds of popular Industry magazines, white papers, webinars, podcasts, and more; all available at no cost to you. With more than 600 complimentary offers, you'll find plenty of titles to suit your professional interests and needs. Click Here and Sign up today!

Sponsored Links

Our Friends

Statistics

Locations of visitors to this page
visitor stats