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

后端 未结 2 1768
一整个雨季
一整个雨季 2020-12-21 04:34

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:



        
2条回答
  •  一整个雨季
    2020-12-21 05:18

    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

提交回复
热议问题