FormattedNumber
public
class
FormattedNumber
extends Object
implements
FormattedValue
java.lang.Object | |
↳ | android.icu.number.FormattedNumber |
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. Instances of this class are immutable and thread-safe.
See also:
Summary
Public methods | |
---|---|
<A extends Appendable>
A
|
appendTo(A appendable)
Appends the formatted string to an Appendable. |
char
|
charAt(int index)
Returns the |
DisplayOptions.NounClass
|
getNounClass()
Gets the noun class of the formatted output. |
MeasureUnit
|
getOutputUnit()
Gets the resolved output unit. |
int
|
length()
Returns the length of this character sequence. |
boolean
|
nextPosition(ConstrainedFieldPosition cfpos)
Iterates over field positions in the FormattedValue. |
CharSequence
|
subSequence(int start, int end)
Returns a |
BigDecimal
|
toBigDecimal()
Export the formatted number as a BigDecimal. |
AttributedCharacterIterator
|
toCharacterIterator()
Exports the formatted number as an AttributedCharacterIterator. |
String
|
toString()
Returns a string representation of the object. |
Inherited methods | |
---|---|
Public methods
appendTo
public A appendTo (A appendable)
Appends the formatted string to an Appendable.
If an IOException occurs when appending to the Appendable, an unchecked
ICUUncheckedIOException
is thrown instead.
Parameters | |
---|---|
appendable |
A : The Appendable to which to append the string output. |
Returns | |
---|---|
A |
The same Appendable, for chaining. |
charAt
public char charAt (int index)
Returns the char
value at the specified index. An index ranges from zero
to length() - 1
. The first char
value of the sequence is at
index zero, the next at index one, and so on, as for array
indexing.
If the char
value specified by the index is a
surrogate, the surrogate
value is returned.
Parameters | |
---|---|
index |
int : the index of the char value to be returned |
Returns | |
---|---|
char |
the specified char value |
getNounClass
public DisplayOptions.NounClass getNounClass ()
Gets the noun class of the formatted output. Returns UNDEFINED
when the noun class is not
supported yet.
Returns | |
---|---|
DisplayOptions.NounClass |
NounClass |
getOutputUnit
public MeasureUnit getOutputUnit ()
Gets the resolved output unit.
The output unit is dependent upon the localized preferences for the usage specified via NumberFormatterSettings.usage(), and may be a unit with MeasureUnit.Complexity.MIXED unit complexity (MeasureUnit.getComplexity()), such as "foot-and-inch" or "hour-and-minute-and-second".
Returns | |
---|---|
MeasureUnit |
MeasureUnit . |
length
public int length ()
Returns the length of this character sequence. The length is the number
of 16-bit char
s in the sequence.
Returns | |
---|---|
int |
the number of char s in this sequence |
nextPosition
public boolean nextPosition (ConstrainedFieldPosition cfpos)
Iterates over field positions in the FormattedValue. This lets you determine the position of specific types of substrings, like a month or a decimal separator. To loop over all field positions:
ConstrainedFieldPosition cfpos = new ConstrainedFieldPosition(); while (fmtval.nextPosition(cfpos)) { // handle the field position; get information from cfpos }
Parameters | |
---|---|
cfpos |
ConstrainedFieldPosition : The object used for iteration state. This can provide constraints to iterate over
only one specific field; see ConstrainedFieldPosition.constrainField . |
Returns | |
---|---|
boolean |
true if a new occurrence of the field was found; false otherwise. |
subSequence
public CharSequence subSequence (int start, int end)
Returns a CharSequence
that is a subsequence of this sequence.
The subsequence starts with the char
value at the specified index and
ends with the char
value at index end - 1
. The length
(in char
s) of the
returned sequence is end - start
, so if start == end
then an empty sequence is returned.
Parameters | |
---|---|
start |
int : the start index, inclusive |
end |
int : the end index, exclusive |
Returns | |
---|---|
CharSequence |
the specified subsequence |
toBigDecimal
public 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 | |
---|---|
BigDecimal |
A BigDecimal representation of the formatted number. |
See also:
toCharacterIterator
public AttributedCharacterIterator toCharacterIterator ()
Exports the formatted number as an AttributedCharacterIterator.
Consider using nextPosition(ConstrainedFieldPosition)
if you are trying to get field information.
Returns | |
---|---|
AttributedCharacterIterator |
An AttributedCharacterIterator containing full field information. |
toString
public String toString ()
Returns a string representation of the object.
Returns | |
---|---|
String |
a string representation of the object. |