Added in API level 26

ScientificNumberFormatter

class ScientificNumberFormatter
kotlin.Any
   ↳ android.icu.text.ScientificNumberFormatter

A formatter that formats numbers in user-friendly scientific notation. ScientificNumberFormatter instances are immutable and thread-safe. Sample code:

ULocale en = new ULocale("en");
  ScientificNumberFormatter fmt = ScientificNumberFormatter.getMarkupInstance(
          en, "<sup>", "</sup>");
  
// Output: "1.23456×10<sup>-78</sup>"
  System.out.println(fmt.format(1.23456e-78));
  

Summary

Public methods
String!
format(number: Any!)

Formats a number

static ScientificNumberFormatter!
getMarkupInstance(locale: ULocale!, beginMarkup: String!, endMarkup: String!)

Gets a ScientificNumberFormatter instance that uses markup for exponents for this locale.

static ScientificNumberFormatter!
getMarkupInstance(df: DecimalFormat!, beginMarkup: String!, endMarkup: String!)

Gets a ScientificNumberFormatter instance that uses markup for exponents.

static ScientificNumberFormatter!

Gets a ScientificNumberFormatter instance that uses superscript characters for exponents for this locale.

static ScientificNumberFormatter!

Gets a ScientificNumberFormatter instance that uses superscript characters for exponents.

Public methods

format

Added in API level 26
fun format(number: Any!): String!

Formats a number

Parameters
number Any!: Can be a double, int, Number or anything that DecimalFormat#format(Object) accepts.
Return
String! the formatted string.

getMarkupInstance

Added in API level 26
static fun getMarkupInstance(
    locale: ULocale!,
    beginMarkup: String!,
    endMarkup: String!
): ScientificNumberFormatter!

Gets a ScientificNumberFormatter instance that uses markup for exponents for this locale.

Parameters
locale ULocale!: The locale
beginMarkup String!: the markup to start superscript e.g <sup>
endMarkup String!: the markup to end superscript e.g </sup>
Return
ScientificNumberFormatter! The ScientificNumberFormatter instance.

getMarkupInstance

Added in API level 26
static fun getMarkupInstance(
    df: DecimalFormat!,
    beginMarkup: String!,
    endMarkup: String!
): ScientificNumberFormatter!

Gets a ScientificNumberFormatter instance that uses markup for exponents.

Parameters
df DecimalFormat!: The DecimalFormat must be configured for scientific notation. Caller may safely change df after this call as this method clones it when creating the ScientificNumberFormatter.
beginMarkup String!: the markup to start superscript e.g <sup>
endMarkup String!: the markup to end superscript e.g </sup>
Return
ScientificNumberFormatter! The ScientificNumberFormatter instance.

getSuperscriptInstance

Added in API level 26
static fun getSuperscriptInstance(locale: ULocale!): ScientificNumberFormatter!

Gets a ScientificNumberFormatter instance that uses superscript characters for exponents for this locale.

Parameters
locale ULocale!: The locale
Return
ScientificNumberFormatter! The ScientificNumberFormatter instance.

getSuperscriptInstance

Added in API level 26
static fun getSuperscriptInstance(df: DecimalFormat!): ScientificNumberFormatter!

Gets a ScientificNumberFormatter instance that uses superscript characters for exponents.

Parameters
df DecimalFormat!: The DecimalFormat must be configured for scientific notation. Caller may safely change df after this call as this method clones it when creating the ScientificNumberFormatter.
Return
ScientificNumberFormatter! the ScientificNumberFormatter instance.