Package com.ibm.icu.impl.icuadapter
Class NumberFormatJDK
java.lang.Object
java.text.Format
com.ibm.icu.text.UFormat
com.ibm.icu.text.NumberFormat
com.ibm.icu.impl.icuadapter.NumberFormatJDK
- All Implemented Interfaces:
Serializable
,Cloneable
NumberFormatJDK is an adapter class which wraps java.text.NumberFormat and
implements ICU4J NumberFormat APIs.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.ibm.icu.text.NumberFormat
NumberFormat.Field, NumberFormat.NumberFormatFactory, NumberFormat.SimpleNumberFormatFactory
Nested classes/interfaces inherited from class com.ibm.icu.text.UFormat
UFormat.SpanField
-
Field Summary
FieldsFields inherited from class com.ibm.icu.text.NumberFormat
ACCOUNTINGCURRENCYSTYLE, CASHCURRENCYSTYLE, CURRENCYSTYLE, FRACTION_FIELD, INTEGER_FIELD, INTEGERSTYLE, ISOCURRENCYSTYLE, NUMBERSTYLE, PERCENTSTYLE, PLURALCURRENCYSTYLE, SCIENTIFICSTYLE, STANDARDCURRENCYSTYLE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()
Overrides clone.boolean
Overrides equals.format
(double number, StringBuffer toAppendTo, FieldPosition pos) Specialization of format.format
(long number, StringBuffer toAppendTo, FieldPosition pos) Specialization of format.format
(BigDecimal number, StringBuffer toAppendTo, FieldPosition pos) Formats an ICU BigDecimal.format
(CurrencyAmount currAmt, StringBuffer toAppendTo, FieldPosition pos) Formats a CurrencyAmount.format
(Object number, StringBuffer toAppendTo, FieldPosition pos) Formats a number and appends the resulting text to the given string buffer.format
(BigDecimal number, StringBuffer toAppendTo, FieldPosition pos) Formats a BigDecimal.format
(BigInteger number, StringBuffer toAppendTo, FieldPosition pos) Formats a BigInteger.Returns the Currency object used to display currency amounts.int
Returns the maximum number of digits allowed in the fraction portion of a number.int
Returns the maximum number of digits allowed in the integer portion of a number.int
Returns the minimum number of digits allowed in the fraction portion of a number.int
int
Returns the rounding mode used in this NumberFormat.int
hashCode()
boolean
Returns true if grouping is used in this format.boolean
Returns true if this format will parse numbers as integers only.boolean
Returns whether strict parsing is in effect.Parses text from the beginning of the given string to produce a number.parse
(String text, ParsePosition parsePosition) Returns a Long if possible (e.g., within the range [Long.MIN_VALUE, Long.MAX_VALUE] and with no decimals); otherwise, returns another type, such as a BigDecimal, BigInteger, or Double.void
setCurrency
(Currency theCurrency) Sets the Currency object used to display currency amounts.void
setGroupingUsed
(boolean newValue) Sets whether or not grouping will be used in this format.void
setMaximumFractionDigits
(int newValue) Sets the maximum number of digits allowed in the fraction portion of a number.void
setMaximumIntegerDigits
(int newValue) Sets the maximum number of digits allowed in the integer portion of a number.void
setMinimumFractionDigits
(int newValue) Sets the minimum number of digits allowed in the fraction portion of a number.void
setMinimumIntegerDigits
(int newValue) Sets the minimum number of digits allowed in the integer portion of a number.void
setParseIntegerOnly
(boolean value) Sets whether to ignore the fraction part of a number when parsing (defaults to false).void
setParseStrict
(boolean value) Sets whether strict parsing is in effect.void
setRoundingMode
(int roundingMode) Set the rounding mode used in this NumberFormat.unwrap()
static NumberFormat
wrap
(NumberFormat jdkNfmt) Methods inherited from class com.ibm.icu.text.NumberFormat
format, format, format, format, format, format, getAvailableLocales, getAvailableULocales, getContext, getCurrencyInstance, getCurrencyInstance, getCurrencyInstance, getEffectiveCurrency, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getIntegerInstance, getIntegerInstance, getIntegerInstance, getMinimumIntegerDigits, getNumberInstance, getNumberInstance, getNumberInstance, getPattern, getPattern, getPatternForStyle, getPatternForStyleAndNumberingSystem, getPercentInstance, getPercentInstance, getPercentInstance, getScientificInstance, getScientificInstance, getScientificInstance, parseCurrency, parseObject, registerFactory, setContext, unregister
Methods inherited from class java.text.Format
format, formatToCharacterIterator, parseObject
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
fJdkNfmt
-
-
Constructor Details
-
NumberFormatJDK
-
-
Method Details
-
wrap
-
unwrap
-
clone
Description copied from class:NumberFormat
Overrides clone.- Overrides:
clone
in classNumberFormat
-
equals
Description copied from class:NumberFormat
Overrides equals. Two NumberFormats are equal they are of the same class and the user-specified values for settings (groupingUsed, parseIntegerOnly, maximumIntegerDigits, etc.) are equal.- Overrides:
equals
in classNumberFormat
- Parameters:
obj
- the object to compare against- Returns:
- true if the object is equal to this.
-
format
Description copied from class:NumberFormat
Formats a BigDecimal. Specialization of format.- Specified by:
format
in classNumberFormat
- See Also:
-
format
Description copied from class:NumberFormat
Formats an ICU BigDecimal. Specialization of format.- Specified by:
format
in classNumberFormat
- See Also:
-
format
Description copied from class:NumberFormat
Formats a BigInteger. Specialization of format.- Specified by:
format
in classNumberFormat
- See Also:
-
format
Description copied from class:NumberFormat
Formats a CurrencyAmount. Specialization of format.- Overrides:
format
in classNumberFormat
- See Also:
-
format
Description copied from class:NumberFormat
Specialization of format.- Specified by:
format
in classNumberFormat
- See Also:
-
format
Description copied from class:NumberFormat
Specialization of format.- Specified by:
format
in classNumberFormat
- See Also:
-
format
Description copied from class:NumberFormat
Formats a number and appends the resulting text to the given string buffer. recognizesBigInteger
andBigDecimal
objects.- Overrides:
format
in classNumberFormat
- See Also:
-
getCurrency
Description copied from class:NumberFormat
Returns the Currency object used to display currency amounts. This may be null.- Overrides:
getCurrency
in classNumberFormat
-
getMaximumFractionDigits
public int getMaximumFractionDigits()Description copied from class:NumberFormat
Returns the maximum number of digits allowed in the fraction portion of a number. The default value is 3, which subclasses can override. When formatting, the exact behavior when this value is exceeded is subclass-specific. When parsing, this has no effect.- Overrides:
getMaximumFractionDigits
in classNumberFormat
- Returns:
- the maximum number of fraction digits
- See Also:
-
getMaximumIntegerDigits
public int getMaximumIntegerDigits()Description copied from class:NumberFormat
Returns the maximum number of digits allowed in the integer portion of a number. The default value is 40, which subclasses can override. When formatting, if the number of digits exceeds this value, the highest- significance digits are truncated until the limit is reached, in accordance with UTS#35. This setting has no effect on parsing.- Overrides:
getMaximumIntegerDigits
in classNumberFormat
- Returns:
- the maximum number of integer digits
- See Also:
-
getMinimumFractionDigits
public int getMinimumFractionDigits()Description copied from class:NumberFormat
Returns the minimum number of digits allowed in the fraction portion of a number. The default value is 0, which subclasses can override. When formatting, if this value is not reached, numbers are padded on the right with the locale-specific '0' character to ensure at least this number of fraction digits. When parsing, this has no effect.- Overrides:
getMinimumFractionDigits
in classNumberFormat
- Returns:
- the minimum number of fraction digits
- See Also:
-
getMinumumIntegerDigits
public int getMinumumIntegerDigits() -
getRoundingMode
public int getRoundingMode()Description copied from class:NumberFormat
Returns the rounding mode used in this NumberFormat. The default implementation of tis method in NumberFormat always throwsUnsupportedOperationException
.- Overrides:
getRoundingMode
in classNumberFormat
- Returns:
- A rounding mode, between
BigDecimal.ROUND_UP
andBigDecimal.ROUND_UNNECESSARY
. - See Also:
-
hashCode
public int hashCode()Description copied from class:NumberFormat
- Overrides:
hashCode
in classNumberFormat
-
isGroupingUsed
public boolean isGroupingUsed()Description copied from class:NumberFormat
Returns true if grouping is used in this format. For example, in the en_US locale, with grouping on, the number 1234567 will be formatted as "1,234,567". The grouping separator as well as the size of each group is locale-dependent and is determined by subclasses of NumberFormat. Grouping affects both parsing and formatting.- Overrides:
isGroupingUsed
in classNumberFormat
- Returns:
- true if grouping is used
- See Also:
-
isParseIntegerOnly
public boolean isParseIntegerOnly()Description copied from class:NumberFormat
Returns true if this format will parse numbers as integers only. For example in the English locale, with ParseIntegerOnly true, the string "1234." would be parsed as the integer value 1234 and parsing would stop at the "." character. The decimal separator accepted by the parse operation is locale-dependent and determined by the subclass.- Overrides:
isParseIntegerOnly
in classNumberFormat
- Returns:
- true if this will parse integers only
-
isParseStrict
public boolean isParseStrict()Description copied from class:NumberFormat
Returns whether strict parsing is in effect.- Overrides:
isParseStrict
in classNumberFormat
- Returns:
- true if strict parsing is in effect
- See Also:
-
parse
Description copied from class:NumberFormat
Parses text from the beginning of the given string to produce a number. The method might not use the entire text of the given string.- Overrides:
parse
in classNumberFormat
- Parameters:
text
- A String whose beginning should be parsed.- Returns:
- A Number parsed from the string.
- Throws:
ParseException
- if the beginning of the specified string cannot be parsed.- See Also:
-
parse
Description copied from class:NumberFormat
Returns a Long if possible (e.g., within the range [Long.MIN_VALUE, Long.MAX_VALUE] and with no decimals); otherwise, returns another type, such as a BigDecimal, BigInteger, or Double. The return type is not guaranteed other than for the Long case.If IntegerOnly is set, will stop at a decimal point (or equivalent; e.g., for rational numbers "1 2/3", will stop after the 1).
Does not throw an exception; if no object can be parsed, index is unchanged!
For more detail on parsing, see the "Parsing" header in the class documentation of
DecimalFormat
.- Specified by:
parse
in classNumberFormat
- See Also:
-
setCurrency
Description copied from class:NumberFormat
Sets the Currency object used to display currency amounts. This takes effect immediately, if this format is a currency format. If this format is not a currency format, then the currency object is used if and when this object becomes a currency format.- Overrides:
setCurrency
in classNumberFormat
- Parameters:
theCurrency
- new currency object to use. May be null for some subclasses.
-
setGroupingUsed
public void setGroupingUsed(boolean newValue) Description copied from class:NumberFormat
Sets whether or not grouping will be used in this format. Grouping affects both parsing and formatting.- Overrides:
setGroupingUsed
in classNumberFormat
- Parameters:
newValue
- true to use grouping.- See Also:
-
setMaximumFractionDigits
public void setMaximumFractionDigits(int newValue) Description copied from class:NumberFormat
Sets the maximum number of digits allowed in the fraction portion of a number. This must be >= minimumFractionDigits. If the new value for maximumFractionDigits is less than the current value of minimumFractionDigits, then minimumFractionDigits will also be set to the new value.- Overrides:
setMaximumFractionDigits
in classNumberFormat
- Parameters:
newValue
- the maximum number of fraction digits to be shown; if less than zero, then zero is used. The concrete subclass may enforce an upper limit to this value appropriate to the numeric type being formatted.- See Also:
-
setMaximumIntegerDigits
public void setMaximumIntegerDigits(int newValue) Description copied from class:NumberFormat
Sets the maximum number of digits allowed in the integer portion of a number. This must be >= minimumIntegerDigits. If the new value for maximumIntegerDigits is less than the current value of minimumIntegerDigits, then minimumIntegerDigits will also be set to the new value.- Overrides:
setMaximumIntegerDigits
in classNumberFormat
- Parameters:
newValue
- the maximum number of integer digits to be shown; if less than zero, then zero is used. Subclasses might enforce an upper limit to this value appropriate to the numeric type being formatted.- See Also:
-
setMinimumFractionDigits
public void setMinimumFractionDigits(int newValue) Description copied from class:NumberFormat
Sets the minimum number of digits allowed in the fraction portion of a number. This must be <= maximumFractionDigits. If the new value for minimumFractionDigits exceeds the current value of maximumFractionDigits, then maximumFractionDigits will also be set to the new value.- Overrides:
setMinimumFractionDigits
in classNumberFormat
- Parameters:
newValue
- the minimum number of fraction digits to be shown; if less than zero, then zero is used. Subclasses might enforce an upper limit to this value appropriate to the numeric type being formatted.- See Also:
-
setMinimumIntegerDigits
public void setMinimumIntegerDigits(int newValue) Description copied from class:NumberFormat
Sets the minimum number of digits allowed in the integer portion of a number. This must be <= maximumIntegerDigits. If the new value for minimumIntegerDigits is more than the current value of maximumIntegerDigits, then maximumIntegerDigits will also be set to the new value.- Overrides:
setMinimumIntegerDigits
in classNumberFormat
- Parameters:
newValue
- the minimum number of integer digits to be shown; if less than zero, then zero is used. Subclasses might enforce an upper limit to this value appropriate to the numeric type being formatted.- See Also:
-
setParseIntegerOnly
public void setParseIntegerOnly(boolean value) Description copied from class:NumberFormat
Sets whether to ignore the fraction part of a number when parsing (defaults to false). If a string contains a decimal point, parsing will stop before the decimal point. Note that determining whether a character is a decimal point depends on the locale.For example, in en-US, parsing the string "123.45" will return the number 123 and parse position 3.
- Overrides:
setParseIntegerOnly
in classNumberFormat
- Parameters:
value
- true if this should parse integers only- See Also:
-
setParseStrict
public void setParseStrict(boolean value) Description copied from class:NumberFormat
Sets whether strict parsing is in effect. When this is true, the string is required to be a stronger match to the pattern than when lenient parsing is in effect. More specifically, the following conditions cause a parse failure relative to lenient mode (examples use the pattern "#,##0.#"):- The presence and position of special symbols, including currency, must match the
pattern.
'+123' fails (there is no plus sign in the pattern) - Leading or doubled grouping separators
',123' and '1,,234" fail - Groups of incorrect length when grouping is used
'1,23' and '1234,567' fail, but '1234' passes - Grouping separators used in numbers followed by exponents
'1,234E5' fails, but '1234E5' and '1,234E' pass ('E' is not an exponent when not followed by a number)
- Overrides:
setParseStrict
in classNumberFormat
- Parameters:
value
- True to enable strict parsing. Default is false.- See Also:
- The presence and position of special symbols, including currency, must match the
pattern.
-
setRoundingMode
public void setRoundingMode(int roundingMode) Description copied from class:NumberFormat
Set the rounding mode used in this NumberFormat. The default implementation of tis method in NumberFormat always throwsUnsupportedOperationException
.- Overrides:
setRoundingMode
in classNumberFormat
- Parameters:
roundingMode
- A rounding mode, betweenBigDecimal.ROUND_UP
andBigDecimal.ROUND_UNNECESSARY
.- See Also:
-