2 *******************************************************************************
\r
3 * Copyright (C) 1996-2008, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
9 package com.ibm.icu.text;
\r
11 import java.lang.reflect.InvocationTargetException;
\r
12 import java.lang.reflect.Method;
\r
13 import java.math.BigInteger;
\r
14 import java.text.DecimalFormatSymbols;
\r
15 import java.text.FieldPosition;
\r
16 import java.text.Format;
\r
17 import java.text.ParseException;
\r
18 import java.text.ParsePosition;
\r
19 import java.util.Locale;
\r
21 import com.ibm.icu.util.ULocale;
\r
24 * <code>NumberFormat</code> is the abstract base class for all number
\r
25 * formats. This class provides the interface for formatting and parsing
\r
26 * numbers. <code>NumberFormat</code> also provides methods for determining
\r
27 * which locales have number formats, and what their names are.
\r
29 * <p><strong>This is an enhanced version of <code>NumberFormat</code> that
\r
30 * is based on the standard version in the JDK. New or changed functionality
\r
32 * <strong><font face=helvetica color=red>NEW</font></strong> or
\r
33 * <strong><font face=helvetica color=red>CHANGED</font></strong>.</strong>
\r
36 * <code>NumberFormat</code> helps you to format and parse numbers for any locale.
\r
37 * Your code can be completely independent of the locale conventions for
\r
38 * decimal points, thousands-separators, or even the particular decimal
\r
39 * digits used, or whether the number format is even decimal.
\r
42 * To format a number for the current Locale, use one of the factory
\r
46 * myString = NumberFormat.getInstance().format(myNumber);
\r
49 * If you are formatting multiple numbers, it is
\r
50 * more efficient to get the format and use it multiple times so that
\r
51 * the system doesn't have to fetch the information about the local
\r
52 * language and country conventions multiple times.
\r
55 * NumberFormat nf = NumberFormat.getInstance();
\r
56 * for (int i = 0; i < a.length; ++i) {
\r
57 * output.println(nf.format(myNumber[i]) + "; ");
\r
61 * To format a number for a different Locale, specify it in the
\r
62 * call to <code>getInstance</code>.
\r
65 * NumberFormat nf = NumberFormat.getInstance(Locale.FRENCH);
\r
68 * You can also use a <code>NumberFormat</code> to parse numbers:
\r
71 * myNumber = nf.parse(myString);
\r
74 * Use <code>getInstance</code> or <code>getNumberInstance</code> to get the
\r
75 * normal number format. Use <code>getIntegerInstance</code> to get an
\r
76 * integer number format. Use <code>getCurrencyInstance</code> to get the
\r
77 * currency number format. And use <code>getPercentInstance</code> to get a
\r
78 * format for displaying percentages. With this format, a fraction like
\r
79 * 0.53 is displayed as 53%.
\r
82 * You can also control the display of numbers with such methods as
\r
83 * <code>setMinimumFractionDigits</code>.
\r
84 * If you want even more control over the format or parsing,
\r
85 * or want to give your users more control,
\r
86 * you can try casting the <code>NumberFormat</code> you get from the factory methods
\r
87 * to a <code>DecimalFormat</code>. This will work for the vast majority
\r
88 * of locales; just remember to put it in a <code>try</code> block in case you
\r
89 * encounter an unusual one.
\r
92 * NumberFormat is designed such that some controls
\r
93 * work for formatting and others work for parsing. The following is
\r
94 * the detailed description for each these control methods,
\r
96 * setParseIntegerOnly : only affects parsing, e.g.
\r
97 * if true, "3456.78" -> 3456 (and leaves the parse position just after '6')
\r
98 * if false, "3456.78" -> 3456.78 (and leaves the parse position just after '8')
\r
99 * This is independent of formatting. If you want to not show a decimal point
\r
100 * where there might be no digits after the decimal point, use
\r
101 * setDecimalSeparatorAlwaysShown on DecimalFormat.
\r
103 * You can also use forms of the <code>parse</code> and <code>format</code>
\r
104 * methods with <code>ParsePosition</code> and <code>FieldPosition</code> to
\r
107 * <li> progressively parse through pieces of a string
\r
108 * <li> align the decimal point and other areas
\r
110 * For example, you can align numbers in two ways:
\r
112 * <li> If you are using a monospaced font with spacing for alignment,
\r
113 * you can pass the <code>FieldPosition</code> in your format call, with
\r
114 * <code>field</code> = <code>INTEGER_FIELD</code>. On output,
\r
115 * <code>getEndIndex</code> will be set to the offset between the
\r
116 * last character of the integer and the decimal. Add
\r
117 * (desiredSpaceCount - getEndIndex) spaces at the front of the string.
\r
119 * <li> If you are using proportional fonts,
\r
120 * instead of padding with spaces, measure the width
\r
121 * of the string in pixels from the start to <code>getEndIndex</code>.
\r
122 * Then move the pen by
\r
123 * (desiredPixelWidth - widthToAlignmentPoint) before drawing the text.
\r
124 * It also works where there is no decimal, but possibly additional
\r
125 * characters at the end, e.g., with parentheses in negative
\r
126 * numbers: "(12)" for -12.
\r
129 * <h4>Synchronization</h4>
\r
131 * Number formats are generally not synchronized. It is recommended to create
\r
132 * separate format instances for each thread. If multiple threads access a format
\r
133 * concurrently, it must be synchronized externally.
\r
136 * <h4>DecimalFormat</h4>
\r
137 * <p>DecimalFormat is the concrete implementation of NumberFormat, and the
\r
138 * NumberFormat API is essentially an abstraction from DecimalFormat's API.
\r
139 * Refer to DecimalFormat for more information about this API.</p>
\r
141 * see DecimalFormat
\r
142 * see java.text.ChoiceFormat
\r
143 * @author Mark Davis
\r
144 * @author Helena Shih
\r
148 public class NumberFormat extends Format {
\r
149 private static final long serialVersionUID = 1;
\r
154 public final java.text.NumberFormat numberFormat;
\r
158 * @param delegate the NumberFormat to which to delegate
\r
160 public NumberFormat(java.text.NumberFormat delegate) {
\r
161 this.numberFormat = delegate;
\r
165 * Default constructor to mirror Java's default public
\r
166 * constructor. Java's is not callable as a public API, since
\r
167 * their NumberFormat is abstract, so this is only useful to
\r
168 * subclasses. In general, subclasses will not work unless
\r
169 * they manipulate the delegate.
\r
171 public NumberFormat() {
\r
172 this.numberFormat = java.text.NumberFormat.getInstance();
\r
176 * Field constant used to construct a FieldPosition object. Signifies that
\r
177 * the position of the integer part of a formatted number should be returned.
\r
178 * @see java.text.FieldPosition
\r
181 public static final int INTEGER_FIELD = 0;
\r
184 * Field constant used to construct a FieldPosition object. Signifies that
\r
185 * the position of the fraction part of a formatted number should be returned.
\r
186 * @see java.text.FieldPosition
\r
189 public static final int FRACTION_FIELD = 1;
\r
192 * <strong><font face=helvetica color=red>CHANGED</font></strong>
\r
193 * Format an object. Change: recognizes <code>BigInteger</code>
\r
194 * and <code>BigDecimal</code> objects.
\r
197 public StringBuffer format(Object number, StringBuffer toAppendTo, FieldPosition pos) {
\r
198 return numberFormat.format(number, toAppendTo, pos);
\r
204 public final Object parseObject(String source, ParsePosition parsePosition) {
\r
205 return numberFormat.parse(source, parsePosition);
\r
209 * Specialization of format.
\r
210 * @see java.text.Format#format(Object)
\r
213 public final String format(double number) {
\r
214 return numberFormat.format(number);
\r
218 * Specialization of format.
\r
219 * @see java.text.Format#format(Object)
\r
222 public final String format(long number) {
\r
223 return numberFormat.format(number);
\r
227 * <strong><font face=helvetica color=red>NEW</font></strong>
\r
228 * Convenience method to format a BigInteger.
\r
231 public final String format(BigInteger number) {
\r
232 return numberFormat.format(number);
\r
236 * Specialization of format.
\r
237 * @see java.text.Format#format(Object, StringBuffer, FieldPosition)
\r
240 public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {
\r
241 return numberFormat.format(number, toAppendTo, pos);
\r
245 * Specialization of format.
\r
246 * @see java.text.Format#format(Object, StringBuffer, FieldPosition)
\r
249 public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) {
\r
250 return numberFormat.format(number, toAppendTo, pos);
\r
254 * <strong><font face=helvetica color=red>NEW</font></strong>
\r
255 * Format a BigInteger.
\r
256 * @see java.text.Format#format(Object, StringBuffer, FieldPosition)
\r
259 public StringBuffer format(BigInteger number, StringBuffer toAppendTo, FieldPosition pos) {
\r
260 return numberFormat.format(number, toAppendTo, pos);
\r
263 * Returns a Long if possible (e.g., within the range [Long.MIN_VALUE,
\r
264 * Long.MAX_VALUE] and with no decimals), otherwise a Double.
\r
265 * If IntegerOnly is set, will stop at a decimal
\r
266 * point (or equivalent; e.g., for rational numbers "1 2/3", will stop
\r
268 * Does not throw an exception; if no object can be parsed, index is
\r
270 * @see #isParseIntegerOnly
\r
271 * @see java.text.Format#parseObject(String, ParsePosition)
\r
274 public Number parse(String text, ParsePosition parsePosition) {
\r
275 return numberFormat.parse(text, parsePosition);
\r
279 * Parses text from the beginning of the given string to produce a number.
\r
280 * The method might not use the entire text of the given string.
\r
282 * @param text A String whose beginning should be parsed.
\r
283 * @return A Number parsed from the string.
\r
284 * @exception ParseException if the beginning of the specified string
\r
285 * cannot be parsed.
\r
289 public Number parse(String text) throws ParseException {
\r
290 return numberFormat.parse(text);
\r
293 * Returns true if this format will parse numbers as integers only.
\r
294 * For example in the English locale, with ParseIntegerOnly true, the
\r
295 * string "1234." would be parsed as the integer value 1234 and parsing
\r
296 * would stop at the "." character. The decimal separator accepted
\r
297 * by the parse operation is locale-dependent and determined by the
\r
299 * @return true if this will parse integers only
\r
302 public boolean isParseIntegerOnly() {
\r
303 return numberFormat.isParseIntegerOnly();
\r
307 * Sets whether or not numbers should be parsed as integers only.
\r
308 * @param value true if this should parse integers only
\r
309 * @see #isParseIntegerOnly
\r
312 public void setParseIntegerOnly(boolean value) {
\r
313 numberFormat.setParseIntegerOnly(value);
\r
316 //============== Locale Stuff =====================
\r
319 * Returns the default number format for the current default locale.
\r
320 * The default format is one of the styles provided by the other
\r
321 * factory methods: getNumberInstance, getIntegerInstance,
\r
322 * getCurrencyInstance or getPercentInstance.
\r
323 * Exactly which one is locale-dependent.
\r
326 public final static NumberFormat getInstance() {
\r
327 return getInstance(ULocale.getDefault(), NUMBERSTYLE);
\r
331 * Returns the default number format for the specified locale.
\r
332 * The default format is one of the styles provided by the other
\r
333 * factory methods: getNumberInstance, getCurrencyInstance or getPercentInstance.
\r
334 * Exactly which one is locale-dependent.
\r
337 public static NumberFormat getInstance(Locale inLocale) {
\r
338 return getInstance(ULocale.forLocale(inLocale), NUMBERSTYLE);
\r
342 * Returns the default number format for the specified locale.
\r
343 * The default format is one of the styles provided by the other
\r
344 * factory methods: getNumberInstance, getCurrencyInstance or getPercentInstance.
\r
345 * Exactly which one is locale-dependent.
\r
348 public static NumberFormat getInstance(ULocale inLocale) {
\r
349 return getInstance(inLocale, NUMBERSTYLE);
\r
353 * Returns a general-purpose number format for the current default locale.
\r
356 public final static NumberFormat getNumberInstance() {
\r
357 return getInstance(ULocale.getDefault(), NUMBERSTYLE);
\r
361 * Returns a general-purpose number format for the specified locale.
\r
364 public static NumberFormat getNumberInstance(Locale inLocale) {
\r
365 return getInstance(ULocale.forLocale(inLocale), NUMBERSTYLE);
\r
369 * Returns a general-purpose number format for the specified locale.
\r
372 public static NumberFormat getNumberInstance(ULocale inLocale) {
\r
373 return getInstance(inLocale, NUMBERSTYLE);
\r
377 * Returns an integer number format for the current default locale. The
\r
378 * returned number format is configured to round floating point numbers
\r
379 * to the nearest integer using IEEE half-even rounding (see {@link
\r
380 * com.ibm.icu.math.BigDecimal#ROUND_HALF_EVEN ROUND_HALF_EVEN}) for formatting,
\r
381 * and to parse only the integer part of an input string (see {@link
\r
382 * #isParseIntegerOnly isParseIntegerOnly}).
\r
384 * @return a number format for integer values
\r
387 public final static NumberFormat getIntegerInstance() {
\r
388 return getInstance(ULocale.getDefault(), INTEGERSTYLE);
\r
392 * Returns an integer number format for the specified locale. The
\r
393 * returned number format is configured to round floating point numbers
\r
394 * to the nearest integer using IEEE half-even rounding (see {@link
\r
395 * com.ibm.icu.math.BigDecimal#ROUND_HALF_EVEN ROUND_HALF_EVEN}) for formatting,
\r
396 * and to parse only the integer part of an input string (see {@link
\r
397 * #isParseIntegerOnly isParseIntegerOnly}).
\r
399 * @param inLocale the locale for which a number format is needed
\r
400 * @return a number format for integer values
\r
403 public static NumberFormat getIntegerInstance(Locale inLocale) {
\r
404 return getInstance(ULocale.forLocale(inLocale), INTEGERSTYLE);
\r
408 * Returns an integer number format for the specified locale. The
\r
409 * returned number format is configured to round floating point numbers
\r
410 * to the nearest integer using IEEE half-even rounding (see {@link
\r
411 * com.ibm.icu.math.BigDecimal#ROUND_HALF_EVEN ROUND_HALF_EVEN}) for formatting,
\r
412 * and to parse only the integer part of an input string (see {@link
\r
413 * #isParseIntegerOnly isParseIntegerOnly}).
\r
415 * @param inLocale the locale for which a number format is needed
\r
416 * @return a number format for integer values
\r
419 public static NumberFormat getIntegerInstance(ULocale inLocale) {
\r
420 return getInstance(inLocale, INTEGERSTYLE);
\r
424 * Returns a currency format for the current default locale.
\r
425 * @return a number format for currency
\r
428 public final static NumberFormat getCurrencyInstance() {
\r
429 return getInstance(ULocale.getDefault(), CURRENCYSTYLE);
\r
433 * Returns a currency format for the specified locale.
\r
434 * @return a number format for currency
\r
437 public static NumberFormat getCurrencyInstance(Locale inLocale) {
\r
438 return getInstance(ULocale.forLocale(inLocale), CURRENCYSTYLE);
\r
442 * Returns a currency format for the specified locale.
\r
443 * @return a number format for currency
\r
446 public static NumberFormat getCurrencyInstance(ULocale inLocale) {
\r
447 return getInstance(inLocale, CURRENCYSTYLE);
\r
451 * Returns a percentage format for the current default locale.
\r
452 * @return a number format for percents
\r
455 public final static NumberFormat getPercentInstance() {
\r
456 return getInstance(ULocale.getDefault(), PERCENTSTYLE);
\r
460 * Returns a percentage format for the specified locale.
\r
461 * @return a number format for percents
\r
464 public static NumberFormat getPercentInstance(Locale inLocale) {
\r
465 return getInstance(ULocale.forLocale(inLocale), PERCENTSTYLE);
\r
469 * Returns a percentage format for the specified locale.
\r
470 * @return a number format for percents
\r
473 public static NumberFormat getPercentInstance(ULocale inLocale) {
\r
474 return getInstance(inLocale, PERCENTSTYLE);
\r
478 * <strong><font face=helvetica color=red>NEW</font></strong>
\r
479 * Returns a scientific format for the current default locale.
\r
480 * @return a scientific number format
\r
483 public final static NumberFormat getScientificInstance() {
\r
484 return getInstance(ULocale.getDefault(), SCIENTIFICSTYLE);
\r
488 * <strong><font face=helvetica color=red>NEW</font></strong>
\r
489 * Returns a scientific format for the specified locale.
\r
490 * @return a scientific number format
\r
493 public static NumberFormat getScientificInstance(Locale inLocale) {
\r
494 return getInstance(ULocale.forLocale(inLocale), SCIENTIFICSTYLE);
\r
498 * <strong><font face=helvetica color=red>NEW</font></strong>
\r
499 * Returns a scientific format for the specified locale.
\r
500 * @return a scientific number format
\r
503 public static NumberFormat getScientificInstance(ULocale inLocale) {
\r
504 return getInstance(inLocale, SCIENTIFICSTYLE);
\r
508 * Get the list of Locales for which NumberFormats are available.
\r
509 * @return the available locales
\r
512 public static Locale[] getAvailableLocales() {
\r
513 return java.text.NumberFormat.getAvailableLocales();
\r
517 * Get the list of Locales for which NumberFormats are available.
\r
518 * @return the available locales
\r
519 * @draft ICU 3.2 (retain)
\r
521 public static ULocale[] getAvailableULocales() {
\r
522 if (availableULocales == null) {
\r
523 Locale[] locales = java.text.NumberFormat.getAvailableLocales();
\r
524 ULocale[] ulocales = new ULocale[locales.length];
\r
525 for (int i = 0; i < locales.length; ++i) {
\r
526 ulocales[i] = ULocale.forLocale(locales[i]);
\r
528 availableULocales = ulocales;
\r
530 return (ULocale[])availableULocales.clone();
\r
532 private static ULocale[] availableULocales;
\r
536 * Returns true if grouping is used in this format. For example, in the
\r
537 * en_US locale, with grouping on, the number 1234567 will be formatted
\r
538 * as "1,234,567". The grouping separator as well as the size of each group
\r
539 * is locale-dependent and is determined by subclasses of NumberFormat.
\r
540 * Grouping affects both parsing and formatting.
\r
541 * @return true if grouping is used
\r
542 * @see #setGroupingUsed
\r
545 public boolean isGroupingUsed() {
\r
546 return numberFormat.isGroupingUsed();
\r
550 * Sets whether or not grouping will be used in this format. Grouping
\r
551 * affects both parsing and formatting.
\r
552 * @see #isGroupingUsed
\r
553 * @param newValue true to use grouping.
\r
556 public void setGroupingUsed(boolean newValue) {
\r
557 numberFormat.setGroupingUsed(newValue);
\r
561 * Returns the maximum number of digits allowed in the integer portion of a
\r
562 * number. The default value is 40, which subclasses can override.
\r
563 * When formatting, the exact behavior when this value is exceeded is
\r
564 * subclass-specific. When parsing, this has no effect.
\r
565 * @return the maximum number of integer digits
\r
566 * @see #setMaximumIntegerDigits
\r
569 public int getMaximumIntegerDigits() {
\r
570 return numberFormat.getMaximumIntegerDigits();
\r
574 * Sets the maximum number of digits allowed in the integer portion of a
\r
575 * number. This must be >= minimumIntegerDigits. If the
\r
576 * new value for maximumIntegerDigits is less than the current value
\r
577 * of minimumIntegerDigits, then minimumIntegerDigits will also be set to
\r
579 * @param newValue the maximum number of integer digits to be shown; if
\r
580 * less than zero, then zero is used. Subclasses might enforce an
\r
581 * upper limit to this value appropriate to the numeric type being formatted.
\r
582 * @see #getMaximumIntegerDigits
\r
585 public void setMaximumIntegerDigits(int newValue) {
\r
586 numberFormat.setMaximumIntegerDigits(newValue);
\r
590 * Returns the minimum number of digits allowed in the integer portion of a
\r
591 * number. The default value is 1, which subclasses can override.
\r
592 * When formatting, if this value is not reached, numbers are padded on the
\r
593 * left with the locale-specific '0' character to ensure at least this
\r
594 * number of integer digits. When parsing, this has no effect.
\r
595 * @return the minimum number of integer digits
\r
596 * @see #setMinimumIntegerDigits
\r
599 public int getMinimumIntegerDigits() {
\r
600 return numberFormat.getMinimumIntegerDigits();
\r
604 * Sets the minimum number of digits allowed in the integer portion of a
\r
605 * number. This must be <= maximumIntegerDigits. If the
\r
606 * new value for minimumIntegerDigits is more than the current value
\r
607 * of maximumIntegerDigits, then maximumIntegerDigits will also be set to
\r
609 * @param newValue the minimum number of integer digits to be shown; if
\r
610 * less than zero, then zero is used. Subclasses might enforce an
\r
611 * upper limit to this value appropriate to the numeric type being formatted.
\r
612 * @see #getMinimumIntegerDigits
\r
615 public void setMinimumIntegerDigits(int newValue) {
\r
616 numberFormat.setMinimumIntegerDigits(newValue);
\r
620 * Returns the maximum number of digits allowed in the fraction
\r
621 * portion of a number. The default value is 3, which subclasses
\r
622 * can override. When formatting, the exact behavior when this
\r
623 * value is exceeded is subclass-specific. When parsing, this has
\r
625 * @return the maximum number of fraction digits
\r
626 * @see #setMaximumFractionDigits
\r
629 public int getMaximumFractionDigits() {
\r
630 return numberFormat.getMaximumFractionDigits();
\r
634 * Sets the maximum number of digits allowed in the fraction portion of a
\r
635 * number. This must be >= minimumFractionDigits. If the
\r
636 * new value for maximumFractionDigits is less than the current value
\r
637 * of minimumFractionDigits, then minimumFractionDigits will also be set to
\r
639 * @param newValue the maximum number of fraction digits to be shown; if
\r
640 * less than zero, then zero is used. The concrete subclass may enforce an
\r
641 * upper limit to this value appropriate to the numeric type being formatted.
\r
642 * @see #getMaximumFractionDigits
\r
645 public void setMaximumFractionDigits(int newValue) {
\r
646 numberFormat.setMaximumFractionDigits(newValue);
\r
650 * Returns the minimum number of digits allowed in the fraction portion of a
\r
651 * number. The default value is 0, which subclasses can override.
\r
652 * When formatting, if this value is not reached, numbers are padded on
\r
653 * the right with the locale-specific '0' character to ensure at least
\r
654 * this number of fraction digits. When parsing, this has no effect.
\r
655 * @return the minimum number of fraction digits
\r
656 * @see #setMinimumFractionDigits
\r
659 public int getMinimumFractionDigits() {
\r
660 return numberFormat.getMinimumFractionDigits();
\r
664 * Sets the minimum number of digits allowed in the fraction portion of a
\r
665 * number. This must be <= maximumFractionDigits. If the
\r
666 * new value for minimumFractionDigits exceeds the current value
\r
667 * of maximumFractionDigits, then maximumFractionDigits will also be set to
\r
669 * @param newValue the minimum number of fraction digits to be shown; if
\r
670 * less than zero, then zero is used. Subclasses might enforce an
\r
671 * upper limit to this value appropriate to the numeric type being formatted.
\r
672 * @see #getMinimumFractionDigits
\r
675 public void setMinimumFractionDigits(int newValue) {
\r
676 numberFormat.setMinimumFractionDigits(newValue);
\r
680 * Return a string suitable for debugging.
\r
681 * @return a string suitable for debugging
\r
682 * @stable ICU 3.4.2
\r
684 public String toString() {
\r
685 return numberFormat.toString();
\r
689 * Overrides Cloneable.
\r
692 public Object clone() {
\r
693 return new NumberFormat((java.text.NumberFormat)numberFormat.clone());
\r
697 * Overrides equals. Two NumberFormats are equal if they are of the same class
\r
698 * and the settings (groupingUsed, parseIntegerOnly, maximumIntegerDigits, etc.
\r
700 * @param obj the object to compare against
\r
701 * @return true if the object is equal to this.
\r
704 public boolean equals(Object obj) {
\r
706 return numberFormat.equals(((NumberFormat)obj).numberFormat);
\r
708 catch (Exception e) {
\r
714 * Overrides hashCode
\r
717 public int hashCode() {
\r
718 return numberFormat.hashCode();
\r
721 // =======================privates===============================
\r
723 private static NumberFormat getInstance(ULocale desiredLocale, int choice) {
\r
724 Locale locale = desiredLocale.toLocale();
\r
725 java.text.NumberFormat nf = null;
\r
727 case NUMBERSTYLE: nf = java.text.NumberFormat.getInstance(locale); break;
\r
728 case CURRENCYSTYLE: nf = java.text.NumberFormat.getCurrencyInstance(locale); break;
\r
729 case PERCENTSTYLE: nf = java.text.NumberFormat.getPercentInstance(locale); break;
\r
730 case SCIENTIFICSTYLE: nf = new java.text.DecimalFormat("#E0", new DecimalFormatSymbols(locale));
\r
731 nf.setMaximumFractionDigits(10);
\r
733 case INTEGERSTYLE:
\r
737 Class[] args = { java.util.Locale.class };
\r
738 integer14API = java.text.NumberFormat.class.getMethod("getIntegerInstance", args);
\r
740 catch (Exception e) {
\r
743 if (integer14API != null) {
\r
745 Object[] args = { locale };
\r
746 nf = (java.text.NumberFormat)integer14API.invoke(null, args);
\r
748 catch (IllegalAccessException e) {
\r
749 integer14API = null;
\r
751 catch (InvocationTargetException e) {
\r
752 integer14API = null;
\r
754 catch (Exception e) {
\r
755 // shouldn't happen, but locale might be null, for example
\r
756 // and we don't want to throw away our method because someone
\r
757 // called us with a bad parameter
\r
761 nf = java.text.NumberFormat.getNumberInstance(locale);
\r
762 nf.setMaximumFractionDigits(0);
\r
763 nf.setParseIntegerOnly(true);
\r
767 return new NumberFormat(nf);
\r
770 private static boolean unchecked = true;
\r
771 private static Method integer14API;
\r
773 private static final int NUMBERSTYLE = 0;
\r
774 private static final int CURRENCYSTYLE = 1;
\r
775 private static final int PERCENTSTYLE = 2;
\r
776 private static final int SCIENTIFICSTYLE = 3;
\r
777 private static final int INTEGERSTYLE = 4;
\r