You do not have to use a different Locale
.
You can use the DecimalFormatSymbols
class to change the symbols that appear in the formatted numbers produced by the format method. These symbols include the decimal separator, the grouping separator, the minus sign, and the percent sign, among others.
The next example demonstrates the DecimalFormatSymbols
class by applying a strange format to a number. The unusual format is the result of the calls to the setDecimalSeparator
, setGroupingSeparator
, and setGroupingSize
methods.
DecimalFormatSymbols unusualSymbols = new DecimalFormatSymbols(currentLocale);
unusualSymbols.setDecimalSeparator('|');
unusualSymbols.setGroupingSeparator('^');
String strange = "#,##0.###";
DecimalFormat weirdFormatter = new DecimalFormat(strange, unusualSymbols);
weirdFormatter.setGroupingSize(4);
String bizarre = weirdFormatter.format(12345.678);
System.out.println(bizarre);
When run, this example prints the number in a bizarre format:
1^2345|678
Taken from: https://docs.oracle.com/javase/tutorial/i18n/format/decimalFormat.html
,
after.
, see docs.oracle.com/javase/8/docs/api/java/text/DecimalFormat.html – Creekmore