Added in API level 30

FormattedNumber


open class FormattedNumber : FormattedValue
kotlin.Any
   ↳ 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.

Summary

Public methods
open A
appendTo(appendable: A)

Appends the formatted string to an Appendable.

open Char
get(index: Int)

Returns the char value at the specified index.

open DisplayOptions.NounClass!

Gets the noun class of the formatted output.

open MeasureUnit!

Gets the resolved output unit.

open Boolean

Iterates over field positions in the FormattedValue.

open CharSequence
subSequence(startIndex: Int, endIndex: Int)

Returns a CharSequence that is a subsequence of this sequence.

open BigDecimal!

Export the formatted number as a BigDecimal.

open AttributedCharacterIterator!

Exports the formatted number as an AttributedCharacterIterator.

open String

Returns a string representation of the object.

Properties
open Int

Returns the length of this character sequence.

Public methods

appendTo

Added in API level 31
open fun <A : Appendable!> appendTo(appendable: A): A

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.
Return
A The same Appendable, for chaining.
Exceptions
android.icu.util.ICUUncheckedIOException if the Appendable throws IOException

get

Added in API level 30
open fun get(index: Int): Char

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
Return
Char the specified char value
Exceptions
java.lang.IndexOutOfBoundsException if the index argument is negative or not less than length()

getNounClass

Added in API level 35
open fun getNounClass(): DisplayOptions.NounClass!

Gets the noun class of the formatted output. Returns UNDEFINED when the noun class is not supported yet.

Return
DisplayOptions.NounClass! NounClass

getOutputUnit

Added in API level 33
open fun getOutputUnit(): MeasureUnit!

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".

Return
MeasureUnit! MeasureUnit.

nextPosition

Added in API level 31
open fun nextPosition(cfpos: ConstrainedFieldPosition!): Boolean

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.
Return
Boolean true if a new occurrence of the field was found; false otherwise.

subSequence

Added in API level 30
open fun subSequence(
    startIndex: Int,
    endIndex: Int
): CharSequence

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 chars) of the returned sequence is end - start, so if start == end then an empty sequence is returned.

Parameters
start the start index, inclusive
end the end index, exclusive
Return
CharSequence the specified subsequence
Exceptions
java.lang.IndexOutOfBoundsException if start or end are negative, if end is greater than length(), or if start is greater than end

toBigDecimal

Added in API level 30
open fun toBigDecimal(): BigDecimal!

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.

Return
BigDecimal! A BigDecimal representation of the formatted number.

toCharacterIterator

Added in API level 30
open fun toCharacterIterator(): AttributedCharacterIterator!

Exports the formatted number as an AttributedCharacterIterator.

Consider using nextPosition if you are trying to get field information.

Return
AttributedCharacterIterator! An AttributedCharacterIterator containing full field information.

toString

Added in API level 30
open fun toString(): String

Returns a string representation of the object.

Return
String The formatted string.

Properties

length

Added in API level 30
open val length: Int

Returns the length of this character sequence. The length is the number of 16-bit chars in the sequence.

Return
Int the number of chars in this sequence