ScientificNumberFormatter
class 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! |
Formats a number |
static ScientificNumberFormatter! |
getMarkupInstance(df: DecimalFormat!, beginMarkup: String!, endMarkup: String!) Gets a ScientificNumberFormatter instance that uses markup for exponents. |
static ScientificNumberFormatter! |
getMarkupInstance(locale: ULocale!, beginMarkup: String!, endMarkup: String!) Gets a ScientificNumberFormatter instance that uses markup for exponents for this locale. |
static ScientificNumberFormatter! |
Gets a ScientificNumberFormatter instance that uses superscript characters for exponents. |
static ScientificNumberFormatter! |
getSuperscriptInstance(locale: ULocale!) Gets a ScientificNumberFormatter instance that uses superscript characters for exponents for this locale. |
Public methods
format
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
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. |
getMarkupInstance
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. |
getSuperscriptInstance
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. |
getSuperscriptInstance
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. |