I have a simple question:
How to get the pattern used to format a number using NumberFormat
created for a specific locale as shown below:
import java.util.Locale;
Locale aLocale = new Locale("fr","CA");
NumberFormat numberFormat=NumberFormat.getNumberInstance(aLocale);
Here I want to know the pattern used to format a number in French
language and the country of Canada
.
For e.g. :
a number 123456.7890
is converted into 123 456,789
after formatting it means pattern may be # ###,###
for above mentioned locale.
The subclasses DecimalFormat and ChoiceFormat have a method toPattern(), so you must check using instanceof and call toPattern()
String pattern = null;
if (numberFormat instanceof DecimalFormat) {
pattern = ((DecimalFormat)numberFormat).toPattern();
}
Consider DecimalFormat.toLocalizedPattern() too
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With