How do I set a default Locale?
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!
Related Examples
- How do I sort items of an ArrayList?
- How do I sort array values in case insensitive order?
- How do I sort array values in descending order?
- How do I convert milliseconds value to date?
- How do I split a string using Scanner class?
- How do I read file using Scanner class?
- How do I read / write data in Windows registry?
- How do I read user input from console using Scanner class?
- How do I use ResourceBundle for i18n?
- How do I convert time between timezone?