import java.util.Locale;
import java.text.NumberFormat;
import java.text.ParseException;
public class NumberLocalizationExample{
@SuppressWarnings("static-access") public static void main(String[] args) {
Locale locale = Locale.CANADA;
String string =
NumberFormat.getNumberInstance(locale).format(-1234.56);
System.out.println("CANADA Format: "+ string);
locale = Locale.GERMAN;
string = NumberFormat.getNumberInstance(
locale).format(-1234.56);
System.out.println("GERMAN Format: "+string);
string = NumberFormat.getNumberInstance().format(-1234.56);
System.out.println("Default Format: "+string);
try {
Number number = NumberFormat.getNumberInstance(
locale.JAPAN).parse("-1.234,56");
if (number instanceof Long) {
System.out.println("Converted Number In Long: "+
number.toString());
} else if (number instanceof Double) {
System.out.println("Converted Number In Double: "+
number.toString());
}
} catch (ParseException e) {
e.printStackTrace();
}
}
}