package org.kodejava.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();
}
}
}
The code snippet output:
Number in Italy: 195.325,75
Number in Japan: 195,325.75
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024