Package com.ibm.icu.number
Class FormattedNumber
- java.lang.Object
-
- com.ibm.icu.number.FormattedNumber
-
public class FormattedNumber extends java.lang.Object
The result of a number formatting operation. This class allows the result to be exported in several data types, including a String, an AttributedCharacterIterator, and a BigDecimal.- See Also:
NumberFormatter
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description <A extends java.lang.Appendable>
AappendTo(A appendable)
Append the formatted number to an Appendable, such as a StringBuilder.boolean
equals(java.lang.Object other)
java.text.AttributedCharacterIterator
getFieldIterator()
Export the formatted number as an AttributedCharacterIterator.PluralRules.IFixedDecimal
getFixedDecimal()
Deprecated.This API is ICU internal only.java.lang.String
getPrefix()
Deprecated.This API is ICU internal only.java.lang.String
getSuffix()
Deprecated.This API is ICU internal only.int
hashCode()
void
populateFieldPosition(java.text.FieldPosition fieldPosition)
Determine the start and end indices of the first occurrence of the given field in the output string.void
populateFieldPosition(java.text.FieldPosition fieldPosition, int offset)
Deprecated.This API is ICU internal only.java.math.BigDecimal
toBigDecimal()
Export the formatted number as a BigDecimal.java.lang.String
toString()
Creates a String representation of the the formatted number.
-
-
-
Method Detail
-
toString
public java.lang.String toString()
Creates a String representation of the the formatted number.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a String containing the localized number.
- See Also:
NumberFormatter
-
appendTo
public <A extends java.lang.Appendable> A appendTo(A appendable)
Append the formatted number to an Appendable, such as a StringBuilder. This may be slightly more efficient than creating a String.If an IOException occurs when appending to the Appendable, an unchecked
ICUUncheckedIOException
is thrown instead.- Parameters:
appendable
- The Appendable to which to append the formatted number string.- Returns:
- The same Appendable, for chaining.
- See Also:
Appendable
,NumberFormatter
-
populateFieldPosition
public void populateFieldPosition(java.text.FieldPosition fieldPosition)
Determine the start and end indices of the first occurrence of the given field in the output string. This allows you to determine the locations of the integer part, fraction part, and sign.If multiple different field attributes are needed, this method can be called repeatedly, or if all field attributes are needed, consider using getFieldIterator().
If a field occurs multiple times in an output string, such as a grouping separator, this method will only ever return the first occurrence. Use getFieldIterator() to access all occurrences of an attribute.
- Parameters:
fieldPosition
- The FieldPosition to populate with the start and end indices of the desired field.- See Also:
NumberFormat.Field
,NumberFormatter
-
populateFieldPosition
@Deprecated public void populateFieldPosition(java.text.FieldPosition fieldPosition, int offset)
Deprecated.This API is ICU internal only.
-
getFieldIterator
public java.text.AttributedCharacterIterator getFieldIterator()
Export the formatted number as an AttributedCharacterIterator. This allows you to determine which characters in the output string correspond to which fields, such as the integer part, fraction part, and sign.If information on only one field is needed, consider using populateFieldPosition() instead.
- Returns:
- An AttributedCharacterIterator, containing information on the field attributes of the number string.
- See Also:
NumberFormat.Field
,AttributedCharacterIterator
,NumberFormatter
-
toBigDecimal
public java.math.BigDecimal toBigDecimal()
Export the formatted number as a BigDecimal. This endpoint is useful for obtaining the exact number being printed after scaling and rounding have been applied by the number formatting pipeline.- Returns:
- A BigDecimal representation of the formatted number.
- See Also:
NumberFormatter
-
getPrefix
@Deprecated public java.lang.String getPrefix()
Deprecated.This API is ICU internal only.
-
getSuffix
@Deprecated public java.lang.String getSuffix()
Deprecated.This API is ICU internal only.
-
getFixedDecimal
@Deprecated public PluralRules.IFixedDecimal getFixedDecimal()
Deprecated.This API is ICU internal only.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
-