Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
374 views
in Technique[技术] by (71.8m points)

java - How to get the pattern of Number Format of a specific locale?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...