How do I set a default Locale?

Bookmark this example!  
Category: java.util, viewed: 1182 time(s).
 
package org.kodejava.example.util;
 
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;
import java.util.Random;
 
public class DefaultLocaleExample {
    public static void main(String[] args) {
        //
        // Use Random class to generate some random number
        //
        Random random = new Random();
 
        //
        // We use the system default locale to format a number.
        //
        NumberFormat formatter = new DecimalFormat();
        Locale locale = Locale.getDefault();
        System.out.println("Locale = " + locale);
        System.out.println(formatter.format(random.nextDouble()));
 
        //
        // We change the default locale to ITALY locale by setting it through the
        // Locale.setDefault() method and then we format another number using a
        // new locale number. This change we'll affect all the class that aware
        // to the Locale, such as the NumberFormat class.
        //
        locale = Locale.ITALY;
        Locale.setDefault(locale);
        formatter = new DecimalFormat();
        System.out.println("Locale = " + locale);
        System.out.println(formatter.format(random.nextDouble()));
    }
}
 
 
Can't find what you are looking for? Join our FORUMS and ask some questions!
Firefox 2
Google

100 Top & Latest

GetJava Download Button

Locations of visitors to this page
eXTReMe Tracker
visitor stats